mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-11 05:29:07 +00:00
Refactored to use the long extension
This commit is contained in:
parent
fa849d39a9
commit
d3bc838477
@ -2,20 +2,16 @@ namespace AIStudio.Tools;
|
||||
|
||||
public static class FileInfoExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the file size in human-readable format.
|
||||
/// </summary>
|
||||
/// <param name="fileInfo">The file info object.</param>
|
||||
/// <returns>The file size in human-readable format.</returns>
|
||||
public static string FileSize(this FileInfo fileInfo)
|
||||
{
|
||||
if (!fileInfo.Exists)
|
||||
return "N/A";
|
||||
|
||||
var size = fileInfo.Length;
|
||||
string[] sizes = { "B", "kB", "MB", "GB", "TB" };
|
||||
var order = 0;
|
||||
while (size >= 1024 && order < sizes.Length - 1)
|
||||
{
|
||||
order++;
|
||||
size /= 1024;
|
||||
}
|
||||
|
||||
return $"{size:0.##} {sizes[order]}";
|
||||
return fileInfo.Length.FileSize();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user