首先,创建DriveInfo的实例-
DriveInfo dInfo = new DriveInfo("E");
显示可用空间-
Console.WriteLine("Disk Free space = {0}", dInfo.AvailableFreeSpace);
现在,使用AvailableFreeSpace属性并获取可用空间的百分比-
Double pc = (dInfo.AvailableFreeSpace / (float)dInfo.TotalSize) * 100;
在这里,您将获得可用大小与总磁盘空间相比的百分比-
Console.WriteLine("\n Free space (percentage) = {0:0.00}%.", pc);