日期:2016-12-14  浏览次数:2498 次

using System.IO;

-----------------------------------

private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();

// GetDrives : 检索计算机上的所有逻辑驱动器的驱动器名称。

foreach (DriveInfo d in allDrives)
{
textBox3.Text = textBox3.Text + d.Name + " " + d.DriveType;
if (d.IsReady == true) //磁盘必须准备好,否则读到光驱就为准备就绪而出错
{
textBox3.Text = textBox3.Text + " " + d.DriveFormat + Environment.NewLine;
}
else
{
textBox3.Text = textBox3.Text + Environment.NewLine;
}

}

}

 

---------------------------------------------------------------

个别说明

name : 盘符

TotalFreeSpace: 返回磁盘可用空间,返回值类型long。

DriveType : 磁盘类型 返回值如下:CDRom(光驱)、Fixed(固定磁盘)、Unknown(未知磁盘)、Network(网络磁盘)、NoRootDirectory(盘符不存在)、Ram(虚拟磁盘)、Removable(可移动磁盘)。

IsReady : 获取一个指示驱动器是否已准备好的值 返回bool类型。

RootDirectory : 获取驱动器根目录。

TotalSize : 空间总大小。

VolumeLabel : 获取驱动器卷标,返回string类型。

DriveFormat : 获取文件系统的名称,例如 NTFS 或 FAT32。