//求磁盘剩余空间
quint64 getDiskFreeSpace(QString driver) {
QString strDiver;
ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes;
LPCWSTR lpcwstrDriver = (LPCWSTR)driver.utf16();
if (!GetDiskFreeSpaceExW(lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes)) {
std::cout << "ERROR: Call to GetDiskFreeSpaceEx() failed.";
return 0;
}
//磁盘总空间
// qDebug() << "liTotalBytes=" << liTotalBytes.QuadPart / 1024 / 1024 / 1024 << "G";
//磁盘剩余空间
// qDebug() << "liTotalFreeBytes=" << liTotalFreeBytes.QuadPart / 1024 / 1024 / 1024 << "G";
return (quint64)liTotalFreeBytes.QuadPart / 1024 / 1024 / 1024;
}
调用:
quint64 freeSpace = getDiskFreeSpace(QString("C:/"));
std::cout << "剩余空间" << freeSpace << "GB"; //输出磁盘剩余空间大小