磁盘容量(GetDiskFreeSpace函数和GetDiskFreeSpaceEx函数)

GetDiskFreeSpace函数和GetDiskFreeSpaceEx函数,主要是用来计算磁盘的各种容量,具体能计算什么,代码中注释得很详细

<pre name="code" class="cpp">#include <Windows.h>
#include <iostream>
using namespace std;
int main()
{
    //得出磁盘的可用空间
    DWORD dwTotalClusters;//总的簇
    DWORD dwFreeClusters;//可用的簇
    DWORD dwSectPerClust;//每个簇有多少个扇区
    DWORD dwBytesPerSect;//每个扇区有多少个字节
    BOOL bResult = GetDiskFreeSpace(TEXT("C:"),&dwSectPerClust, &dwBytesPerSect, &dwFreeClusters, &dwTotalClusters);
    if(bResult){
        cout << "使用GetDiskFreeSpace函数获取磁盘空间信息" << endl;
        cout << "总簇数量: " << dwTotalClusters << endl;
        cout << "可用的簇: " << dwFreeClusters << endl;
        cout << "每个簇有多少个扇区: " << dwSectPerClust << endl;
        cout << "每个扇区有多少个字节: " <<  dwBytesPerSect << endl;
        cout << "磁盘总容量: " <<  dwTotalClusters * (DWORD64)dwSectPerClust * (DWORD64)dwBytesPerSect << endl;
        cout << "磁盘空闲容量: " << dwFreeClusters * (DWORD64)dwSectPerClust * (DWORD64)dwBytesPerSect << endl;
    }
    cout << "\n\n" << endl;

    DWORD64 qwFreeBytes, qwFreeBytesToCaller, qwTotalBytes;
    bResult = GetDiskFreeSpaceEx(TEXT("C:"), 
	(PULARGE_INTEGER)&qwFreeBytesToCaller, 
	(PULARGE_INTEGER)&qwTotalBytes, 
	(PULARGE_INTEGER)&qwFreeBytes);
    if(bResult){
        cout << "使用GetDiskFreeSpaceEx函数获取磁盘空间信息" << endl;
        cout << "磁盘总容量: " <<  qwTotalBytes << endl;
        cout << "可用的磁盘空闲容量: " << qwFreeBytes << endl;
        cout << "磁盘空闲容量: " << qwFreeBytesToCaller << endl;
    }
    system("pause");
}


 

运行结果


  • 7
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值