4.5 使用GetDiskFreeSpace函数获取磁盘空间信息

效果

源码

#include

#include

//获取磁盘空间信息

BOOL GetDiskSpaceInfo(LPCSTR pszDrive){

DWORD64 qwFreeBytesToCaller;

DWORD64 qwTotalBytes;

DWORD64 qwFreeBytes;

DWORD dwSectPerClust;

DWORD dwBytesPerSect;

DWORD dwFreeClusters;

DWORD dwTotalClusters;

BOOL bResult;

//获取和打印磁盘信息

bResult = GetDiskFreeSpaceEx(

pszDrive,

(PULARGE_INTEGER)&qwFreeBytesToCaller,

(PULARGE_INTEGER)&qwTotalBytes,

(PULARGE_INTEGER)&qwFreeBytes

);

if (bResult){

printf("使用GetDiskFreeSpaceEx函数获取磁盘空间信息:\n");

printf("可获得的空闲空间: %I64d 字节\n",qwFreeBytesToCaller);

printf("空闲空间: %I64d 字节\n", qwFreeBytes);

printf("磁盘总容量: %I64d 字节\n", qwTotalBytes);

}

bResult = GetDiskFreeSpace(

pszDrive,

&dwSectPerClust,

&dwBytesPerSect,

&dwFreeClusters,

&dwTotalClusters

);

if (bResult){

printf("\n使用GetDiskFreeSpace函数获取磁盘空间信息:\n");

printf("总簇数: %d\n", dwTotalClusters);

printf("空闲的簇数: %d\n", dwFreeClusters);

printf("每簇扇区数: %d\n", dwSectPerClust);

printf("每扇区容量: %d 字节\n", dwBytesPerSect);

printf("磁盘总容量: %I64d 字节\n", (DWORD64)dwTotalClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect);

printf("空闲大小: %I64d 字节\n", (DWORD64)dwFreeClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect);

}

return bResult;

}

int wmain(int argc, PCHAR argv[]){

GetDiskSpaceInfo(argv[1]);

getchar();

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容