namespace AipGateway.API.Application.Utils { public class AipFileUtils { public static string fileSizeFormatBytes(long bytes) { const int scale = 1024; string[] orders = new string[] { "GB", "MB", "KB", "Bytes" }; long max = (long)Math.Pow(scale, orders.Length - 1); foreach (string order in orders) { if (bytes > max) return string.Format("{0:##.##} {1}", decimal.Divide(bytes, max), order); max /= scale; } return "0 Bytes"; } public static bool isExists(String fileName) { return File.Exists(fileName); } public static String getFileName(String fileName) { return Path.GetFileName(fileName); } public static String getFileNameWithoutExtension(String fileName) { return Path.GetFileNameWithoutExtension(fileName); } public static String getExtension(String fileName) { String fileExt = Path.GetExtension(fileName).ToLower(); if (fileExt == null) { return "."; } return fileExt; } public static void delete(string fileName) { try { if (File.Exists(fileName)) { File.Delete(fileName); } } catch (Exception) { } } } }