DeadByDaylightBackup.Utility/FileUtility.cs
/// <summary>
/// Get the size of a file in readable style
/// </summary>
/// <param name="fileName">filepath</param>
/// <returns>Readable string like "2.96 KB"</returns>
Get the size of a file in readable style
Get the size of a file in readable style
public static string GetReadableFileSize(string fileName)
        {
            string[] sizes = { "B", "KB", "MB", "GB", "TB" };
            double len = GetFileSize(fileName);
            int order = 0;
            while (len >= 1024 && order < sizes.Length - 1)
            {
                order++;
                len = len / 1024;
            }
            string result = String.Format("{0:0.##} {1}", len, sizes[order]);
            return result;
        }
public static string GetReadableFileSize ( string fileName ) { string [ ] sizes = { " " , " " , " " , " " , " " } ; double len = GetFileSize ( fileName ) ; int order = 0 ; while ( len >= 1024 && order < sizes . Length - 1 ) { order ++ ; len = len / 1024 ; } string result = String . Format ( " " , len , sizes [ order ] ) ; return result ; }
Get the size of a file in readable style
Get the size of a file in readable style
Readable string like "2.96 KB"
Readable string like " 2 . 96 KB "
fileName
string
None