quint64 getDiskFreeSpace(QString driver)
{
LPCWSTR lpcwstrDriver=(LPCWSTR)driver.utf16();
ULARGE_INTEGER liFreeBytesAvailable, liTotalBytes, liTotalFreeBytes;
if( !GetDiskFreeSpaceEx( lpcwstrDriver, &liFreeBytesAvailable, &liTotalBytes, &liTotalFreeBytes) )
{
qDebug() << "ERROR: Call to GetDiskFreeSpaceEx() failed.";
return 0;
}
return (quint64) liTotalFreeBytes.QuadPart/1024/1024/1024;
}
//调用时:
quint64 freeSpace =getDiskFreeSpace(QString("C:/"));
qDebug() << "剩余空间 " << freeSpace<< "GB";//输出磁盘剩余空间大小
原文:http://www.cnblogs.com/lvdongjie/p/3795804.html