如何计算的可用磁盘空间? [英] How to calculate free disk space?
本文介绍了如何计算的可用磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我工作的一个安装项目中,我需要将文件解压到硬盘。如何计算/查找可用磁盘空间的硬盘上使用C#?
I'm working on an installer project where I need to extract files to the disk. How can I calculate/find the disk space available on hard disk using c#?
推荐答案
<一个href="http://msdn.microsoft.com/en-us/library/system.io.driveinfo.totalfreespace.aspx">http://msdn.microsoft.com/en-us/library/system.io.driveinfo.totalfreespace.aspx
从链接复制
using System;
using System.IO;
class Test
{
public static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
Console.WriteLine("Drive {0}", d.Name);
Console.WriteLine(" File type: {0}", d.DriveType);
if (d.IsReady == true)
{
Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
Console.WriteLine(" File system: {0}", d.DriveFormat);
Console.WriteLine(
" Available space to current user:{0, 15} bytes",
d.AvailableFreeSpace);
Console.WriteLine(
" Total available space: {0, 15} bytes",
d.TotalFreeSpace);
Console.WriteLine(
" Total size of drive: {0, 15} bytes ",
d.TotalSize);
}
}
}
}
这篇关于如何计算的可用磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文