基础功能,用于个人备忘录
//获取盘符可用空间 drive同时可以可以获取磁盘分区容量等
在这里插入代码片
#endregion
#region drive.TotalFreeSpace单位为bit,根据需要除以1024。str_HardDiskName输入D,代表D盘,下面有增加:\\
public static long GetHardDiskSpace(string str_HardDiskName)
{
//long totalSize = 0;
long totalSize = new long();
str_HardDiskName = str_HardDiskName + ":\\";
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
if (drive.Name == str_HardDiskName)
{
totalSize = drive.TotalFreeSpace / (1024 * 1024 * 1024);
}
}
return totalSize;
}
#endregion
获取磁盘总空间
在这里插入代码片
#region 获取磁盘总空间
public static long GetHardDiskTotalSpace(string str_HardDiskName)
{
//long totalSize = 0;
long totalSize = new long();
str_HardDiskName = str_HardDiskName + ":\\";
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
if (drive.Name == str_HardDiskName)
{
totalSize = drive.TotalSize /(1024 * 1024 * 1024);
}
}
return totalSize;
}
#endregion