Find free disk space using C#

CsharpProgrammingServer Side Programming

Firstly, create an instance of DriveInfo −

DriveInfo dInfo = new DriveInfo("E");

Display free space −

Console.WriteLine("Disk Free space = {0}", dInfo.AvailableFreeSpace);

Now, use 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 in comparison with the total disk space −

Console.WriteLine("\n Free space (percentage) = {0:0.00}%.", pc);
Published on 21-Aug-2018 15:47:13