Added file info extensions

This commit is contained in:
Thorsten Sommer 2025-01-23 09:42:05 +01:00
parent 9ce140c16b
commit 094daedee1
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -0,0 +1,21 @@
namespace AIStudio.Tools;
public static class FileInfoExtensions
{
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]}";
}
}