gpt4 book ai didi

c# - 总可用空间检测不适用于大型硬盘驱动器?

转载 作者:太空狗 更新时间:2023-10-29 22:35:48 27 4
gpt4 key购买 nike

我正在使用 c# 程序查看硬盘驱动器上仍有多少 GB 可用(总大小 1 TB,可用大小 110 GB(确切地说,根据 Windows 中的驱动器属性资源管理器:118.333.329.408 字节)根据 Windows)。

我的问题是我得到的结果是......关闭。

根据我在下面使用的 C# 方法,它是 10,135,252,992 字节......但根据 Windows 110! GB 是免费的。

注意:我这里说的是Windows Server,驱动器是D盘。所以它上面没有交换文件,也没有隐藏的系统文件(至少不超过任何非系统驱动器,因为系统驱动器是 C 驱动器)。

public long GetTotalFreeSpace(string driveName)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
{
if (drive.IsReady && drive.Name == driveName)
{
return drive.TotalFreeSpace;
}
}
return -1;
}

我的问题是这怎么可能以及如何纠正它?

最佳答案

在引擎盖下,System.IO.DriveInfo assembly似乎使用 GetDiskFreeSpaceEx function来自 Windows API。

标准版 GetDiskFreeSpaceGetDiskFreeSpaceEx 的区别在于:

获取磁盘可用空间:

GetDiskFreeSpace function Retrieves information about the specified disk, including the amount of free space on the disk.

GetDiskFreeSpaceEx:

GetDiskFreeSpaceEx function Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.

很可能,您正在达到当前用户可用空间的一些配额。

关于c# - 总可用空间检测不适用于大型硬盘驱动器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47830215/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com