本文整理汇总了C#中System.IO.DriveInfo.AvailableFreeSpace属性的典型用法代码示例。如果您正苦于以下问题:C# DriveInfo.AvailableFreeSpace属性的具体用法?C# DriveInfo.AvailableFreeSpace怎么用?C# DriveInfo.AvailableFreeSpace使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.IO.DriveInfo
的用法示例。
在下文中一共展示了DriveInfo.AvailableFreeSpace属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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(" Drive 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);
}
}
}
}
输出:
Drive A:\ Drive type: Removable Drive C:\ Drive type: Fixed Volume label: File system: FAT32 Available space to current user: 4770430976 bytes Total available space: 4770430976 bytes Total size of drive: 10731683840 bytes Drive D:\ Drive type: Fixed Volume label: File system: NTFS Available space to current user: 15114977280 bytes Total available space: 15114977280 bytes Total size of drive: 25958948864 bytes Drive E:\ Drive type: CDRom The actual output of this code will vary based on machine and the permissions granted to the user executing it.
示例2: Main
//引入命名空间
using System;
using System.IO;
class MainClass {
static void Main(string[] args) {
FileInfo file = new FileInfo("c:\\a.txt");
// Display drive information.
DriveInfo drv = new DriveInfo(file.FullName);
Console.Write("Drive: ");
Console.WriteLine(drv.Name);
if (drv.IsReady) {
Console.Write("Drive free space: ");
Console.WriteLine(drv.AvailableFreeSpace.ToString());
}
}
}