[DllImport("kernel32.dll")]
private static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
/// <summary>
/// 取得磁盤剩余空間
/// </summary>
/// <param name="driveDirectoryName">驅(qū)動器名</param>
/// <returns>剩余空間</returns>
private static ulong GetFreeSpace(string driveDirectoryName)
{
ulong freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
if (!driveDirectoryName.EndsWith(":\\"))
{
driveDirectoryName += ":\\";
}
GetDiskFreeSpaceEx(driveDirectoryName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes);
return freeBytesAvailable;
}
private static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
/// <summary>
/// 取得磁盤剩余空間
/// </summary>
/// <param name="driveDirectoryName">驅(qū)動器名</param>
/// <returns>剩余空間</returns>
private static ulong GetFreeSpace(string driveDirectoryName)
{
ulong freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
if (!driveDirectoryName.EndsWith(":\\"))
{
driveDirectoryName += ":\\";
}
GetDiskFreeSpaceEx(driveDirectoryName, out freeBytesAvailable, out totalNumberOfBytes, out totalNumberOfFreeBytes);
return freeBytesAvailable;
}