效果
源碼
#include
#include
//獲取磁盤(pán)空間信息
BOOL GetDiskSpaceInfo(LPCSTR pszDrive){
DWORD64 qwFreeBytesToCaller;
DWORD64 qwTotalBytes;
DWORD64 qwFreeBytes;
DWORD dwSectPerClust;
DWORD dwBytesPerSect;
DWORD dwFreeClusters;
DWORD dwTotalClusters;
BOOL bResult;
//獲取和打印磁盤(pán)信息
bResult = GetDiskFreeSpaceEx(
pszDrive,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes
);
if (bResult){
printf("使用GetDiskFreeSpaceEx函數(shù)獲取磁盤(pán)空間信息:\n");
printf("可獲得的空閑空間: %I64d 字節(jié)\n",qwFreeBytesToCaller);
printf("空閑空間: %I64d 字節(jié)\n", qwFreeBytes);
printf("磁盤(pán)總?cè)萘? %I64d 字節(jié)\n", qwTotalBytes);
}
bResult = GetDiskFreeSpace(
pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters
);
if (bResult){
printf("\n使用GetDiskFreeSpace函數(shù)獲取磁盤(pán)空間信息:\n");
printf("總簇?cái)?shù): %d\n", dwTotalClusters);
printf("空閑的簇?cái)?shù): %d\n", dwFreeClusters);
printf("每簇扇區(qū)數(shù): %d\n", dwSectPerClust);
printf("每扇區(qū)容量: %d 字節(jié)\n", dwBytesPerSect);
printf("磁盤(pán)總?cè)萘? %I64d 字節(jié)\n", (DWORD64)dwTotalClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect);
printf("空閑大小: %I64d 字節(jié)\n", (DWORD64)dwFreeClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect);
}
return bResult;
}
int wmain(int argc, PCHAR argv[]){
GetDiskSpaceInfo(argv[1]);
getchar();
}