效果
源码
#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();
}
网友评论