#include <Windows.h> #include <stdio.h> int main() { BOOL bResult; // 簇 DWORD dwTotalClusters; // 扇区 DWORD dwSectPerClust; // 字节 DWORD dwBytesPerSect; // 空闲簇 DWORD dwFreeClusters; bResult = GetDiskFreeSpace(TEXT("C:"),&dwSectPerClust,&dwBytesPerSect,&dwFreeClusters,&dwTotalClusters); if(bResult) { printf("使用GetDiskFreeSpace获取磁盘空间信息\n"); printf("总簇的数量:\t\t\t%d\n",dwTotalClusters); printf("每簇的扇区数量:\t\t%d\n",dwSectPerClust); printf("每扇区的字节数:\t\t%d\n",dwBytesPerSect); printf("空闲簇数量:\t\t%d\n",dwFreeClusters); printf("磁盘总容量:\t\t\t%I64d\n",(DWORD64)dwTotalClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect); printf("磁盘空闲容量:\t\t\t%I64d\n",(DWORD64)dwFreeClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBytesPerSect); } printf("\n\n"); DWORD64 qwFreeBytes, qwFreeBytesToCaller, qwTotalBytes; bResult = GetDiskFreeSpaceEx(TEXT("C:"), (PULARGE_INTEGER)&qwFreeBytesToCaller, (PULARGE_INTEGER)&qwTotalBytes, (PULARGE_INTEGER)&qwFreeBytes); if(bResult) { printf("磁盘总容量:\t\t\t%I64d\n", qwTotalBytes); printf("可用磁盘空闲容量:\t\t%I64d\n",qwFreeBytes); printf("磁盘空闲容量:\t\t\t%I64d\n", qwFreeBytesToCaller); } system("pause"); return 0; }
时间: 2024-11-05 21:58:40