You can see the sample with NtQueryDirectoryFile I had posted in this thread
(you can find simpler methods, a bit slower, like the samples from IronRazerz in this thread (in VB, but same code in C#))
How to calculate Folder size in C# WindowsForms
Andi
111
Reputation points
Hi i am already able to calculate the size of Files but i want to calulate the size of a folder on a similar way and with the conversion.
How can i convert my actual programm to easily calulate folder sizes?
FileInfo di = new FileInfo(@"C:\Users\icon.ico");
if (di.Length >= 1073741824.0)
{
textBox13.Text = String.Format("{0:##.##}", di.Length / 1073741824.0) + " GB";
}
else if (di.Length >= 1048576.0)
{
textBox13.Text = String.Format("{0:##.##}", di.Length / 1048576.0) + " MB";
}
else if (di.Length >= 1024.0)
textBox13.Text = String.Format("{0:##.##}", di.Length / 1024.0) + " KB";
else if (di.Length > 0 && di.Length < 1024.0)
textBox13.Text = di.Length.ToString() + " KB";
Thanks for your help in advice!
1 answer
Sort by: Most helpful
-
Castorix31 83,206 Reputation points
2022-10-14T11:44:53.967+00:00