头文件:#include <sys/vfs.h>

statfs这个函数,功能类似于df命令。

struct statfs diskInfo;
statfs(ent.dir_path.c_str(), &diskInfo);
unsigned long long totalBlocks = diskInfo.f_bsize;
unsigned long long totalSize = totalBlocks * diskInfo.f_blocks;
size_t mbTotalsize = totalSize>>20;
unsigned long long freeDisk = diskInfo.f_bfree*totalBlocks;
size_t mbFreedisk = freeDisk>>20;
printf("%s total=%dMB, free=%dMB\n", ent.dir_path.c_str(), mbTotalsize, mbFreedisk);
本文链接地址:https://const.net.cn/545.html

标签: none

添加新评论