QT — get hard disk margin

header file:

#include < windows.h>

implementation:

quint64 ImageSave::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;//返回单位G
}


Read More: