mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-02-11 16:09:06 +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
|
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)
|
public static string FileSize(this FileInfo fileInfo)
|
||||||
{
|
{
|
||||||
if (!fileInfo.Exists)
|
if (!fileInfo.Exists)
|
||||||
return "N/A";
|
return "N/A";
|
||||||
|
|
||||||
var size = fileInfo.Length;
|
return fileInfo.Length.FileSize();
|
||||||
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]}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user