获得驱动器使用空间的百分比

问题描述:

我发现了以下这篇文章,它给了我想要的(how to find the free percentage of a drive in c#)的反函数,但我无法完全理解如何将驱动器的USED空间作为百分比返回。获得驱动器使用空间的百分比

+0

OO 100 what_you_get链接的答案吗? –

+0

er ... 100 - {free space as percentage}? :) –

+0

我投票结束这个问题作为题外话,因为它是关于基本的数学,而不是编程。 –

它几乎是一样一样

DriveInfo drive = new DriveInfo("C"); 
double percentFree = 100 * (double)(drive.TotalSize - drive.AvailableFreeSpace)/drive.TotalSize; 

DriveInfo drive = new DriveInfo("C"); 
var totalUsed = drive.TotalSize-drive.TotalFreeSpace; 
var percentUsed = 100 * (double)totalUsed/drive.TotalSize;