mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-15 02:13:48 +00:00
Added file info extensions
This commit is contained in:
1 file changed
+21
@@ -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]}";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user