学习API之获取磁盘信息

#include <windows.h>
#include <stdio.h>

/************************************
* BOOL GetDiskSpaceInfo(LPSTR pszDrive)
* 功能:根据输入磁盘驱动器,获取磁盘信息
* 参数:LPSTR pszDrive
驱动器根路径,如 D:
************************************/

BOOL GetDiskSpaceInfo(LPSTR pszDrive)
{
DWORD64 qwFreeBytesToCaller, qwTotalBytes, qwFreeBytes;
DWORD dwSectPerClust, dwBtyesPerSect, dwFreeClusters, dwTotalClusters;
BOOL bResult;
bResult = GetDiskFreeSpaceEx(pszDrive,
(PULARGE_INTEGER)&qwFreeBytesToCaller,
(PULARGE_INTEGER)&qwTotalBytes,
(PULARGE_INTEGER)&qwFreeBytes);
if (bResult)
{
printf("使用GetDiskFreeSpaceEx获取磁盘信息\n");
printf("可获取的空闲空间(字节):\t%I64d\n", qwFreeBytesToCaller);
printf("空闲空间(字节):\t\t%I64d\n",qwFreeBytes);
printf("磁盘总容量(字节):\t\t%I64d\n",qwTotalBytes);
}
bResult = GetDiskFreeSpace(pszDrive,
&dwSectPerClust,
&dwBtyesPerSect,
&dwFreeClusters,
&dwTotalClusters);
if (bResult)
{
printf("\n使用GetDiskFreeSpace获取磁盘空间信息\n");
printf("空闲的镞数量:\t\t\t%d\n",dwFreeClusters);
printf("总镞数量:\t\t\t%d\n", dwTotalClusters);
printf("每镞的扇区数量:\t\t\t%d\n", dwSectPerClust);
printf("每扇区的容量(字节):\t\t\t%d\n",dwBtyesPerSect);
printf("空闲空间(字节):\t\t%I64d\n", (DWORD64)dwTotalClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBtyesPerSect);
printf("磁盘总容量(字节):\t\t%I64d", (DWORD64)dwTotalClusters*(DWORD64)dwSectPerClust*(DWORD64)dwBtyesPerSect);
}
return bResult;
}
int main(int argc, PCHAR argv[])
{
GetDiskSpaceInfo(argv[1]);
}

使用实例:

转载于:https://www.cnblogs.com/zjf94/p/5503116.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值