gpt4 book ai didi

c - 如何使用 C 从 Windows 获取可用磁盘空间?

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:44 24 4
gpt4 key购买 nike

我有 1 个磁盘被分成多个分区。我想获得每个分区上可用的可用空间,以确定最适合放置文件的位置。

我如何在 C 中执行此操作?

我一直在尝试使用这段代码:

__int64 lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes;
DWORD dwSectPerClust, dwBytesPerSect, dwFreeClusters, dwTotalClusters;

test = GetDiskFreeSpaceEx(
pszDrive,
(PULARGE_INTEGER)&lpFreeBytesAvailable,
(PULARGE_INTEGER)&lpTotalNumberOfBytes,
(PULARGE_INTEGER)&lpTotalNumberOfFreeBytes
);

但结果不正确。

有什么想法吗?

谢谢

最佳答案

这对我来说很好:

 void main (int argc, wchar_t **argv)
{
BOOL fResult;
unsigned __int64 i64FreeBytesToCaller,
i64TotalBytes,
i64FreeBytes;
fResult = GetDiskFreeSpaceEx (L"C:",
(PULARGE_INTEGER)&i64FreeBytesToCaller,
(PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult)
{
printf ("\n\nGetDiskFreeSpaceEx reports\n\n");
printf ("Available space to caller = %I64u MB\n",
i64FreeBytesToCaller / (1024*1024));
printf ("Total space = %I64u MB\n",
i64TotalBytes / (1024*1024));
printf ("Free space on drive = %I64u MB\n",
i64FreeBytes / (1024*1024));
}
}

关于c - 如何使用 C 从 Windows 获取可用磁盘空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917946/

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