Home > Article > Backend Development > Find available disk space using C#
First, create an instance of DriveInfo-
DriveInfo dInfo = new DriveInfo("E");
Display available space-
Console.WriteLine("Disk Free space = {0}", dInfo.AvailableFreeSpace);
Now, use the AvailableFreeSpace property and get the percentage of free space-
Double pc = (dInfo.AvailableFreeSpace / (float)dInfo.TotalSize) * 100;
Here you will get the percentage of free size to total disk space -
Console.WriteLine(" Free space (percentage) = {0:0.00}%.", pc);
The above is the detailed content of Find available disk space using C#. For more information, please follow other related articles on the PHP Chinese website!