C# 计算硬盘剩余空间

C# 计算硬盘剩余空间

猿掌柜
2023-07-18 / 0 评论 / 10 阅读 / 正在检测是否收录...
代码如下
public static long GetHardDiskFreeSpace(string str_HardDiskName)

        {
            long freeSpace = new long();
            str_HardDiskName = str_HardDiskName + ":\\";
            DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in drives)

            {
                if (drive.Name == str_HardDiskName)
                {
                    freeSpace = drive.TotalFreeSpace / (1024 * 1024 * 1024);
                }
            }
            return freeSpace;
        }
2

评论 (0)

取消