Introduction
This code is used to check for free space available on logical disks.
How to use it
Copy the source files HardDiskManager.cpp and HardDiskManager.h to your project directory and add them to your project.
CHardDiskManager::CHardDiskManager()
{
m_uliFreeBytesAvailable.QuadPart = 0L;
m_uliTotalNumberOfBytes.QuadPart = 0L;
m_uliTotalNumberOfFreeBytes.QuadPart = 0L;
}
CHardDiskManager::~CHardDiskManager()
{
}
bool CHardDiskManager::CheckFreeSpace(LPCTSTR lpDirectoryName)
{
if( !GetDiskFreeSpaceEx(
lpDirectoryName,
&m_uliFreeBytesAvailable,
&m_uliTotalNumberOfBytes,
&m_uliTotalNumberOfFreeBytes) )
return false;
return true;
}
DWORD64 CHardDiskManager::GetFreeBytesAvailable(void)
{
return m_uliFreeBytesAvailable.QuadPart;
}
DWORD64 CHardDiskManager::GetTotalNumberOfBytes(void)
{
return m_uliTotalNumberOfBytes.QuadPart;
}
DWORD64 CHardDiskManager::GetTotalNumberOfFreeBytes(void)
{
return m_uliTotalNumberOfFreeBytes.QuadPart;
}
double CHardDiskManager::GetFreeGBytesAvailable(void)
{
return (double)(
(signed __int64)(m_uliFreeBytesAvailable.QuadPart) /
1.0e9
);
}
double CHardDiskManager::GetTotalNumberOfGBytes(void)
{
return (double)(
(signed __int64)(m_uliTotalNumberOfBytes.QuadPart) /
1.0e9
);
}
double CHardDiskManager::GetTotalNumberOfFreeGBytes(void)
{
return (double)(
(signed __int64)(m_uliTotalNumberOfFreeBytes.QuadPart) /
1.0e9
);
}
#include "HardDiskManager.h"
using namespace std;
void main( int argc, char** argv )
{
CHardDiskManager manager;
manager.CheckFreeSpace("c:");
cout << "Drive C:\\" << endl;
cout << "FreeBytesAvailable: " <<
manager.GetFreeGBytesAvailable() <<
" GBytes. " << endl;
cout << "TotalNumberOfBytes: " <<
manager.GetTotalNumberOfGBytes()
<< " GBytes. " << endl;
cout << "TotalNumberOfFreeBytes: " <<
manager.GetTotalNumberOfFreeGBytes() <<
" GBytes. " << endl;
manager.CheckFreeSpace("d:");
cout << "Drive D:\\" << endl;
cout << "FreeBytesAvailable: " <<
manager.GetFreeGBytesAvailable()
<< " GBytes. " << endl;
cout << "TotalNumberOfBytes: " <<
manager.GetTotalNumberOfGBytes()
<< " GBytes. " << endl;
cout << "TotalNumberOfFreeBytes: " <<
manager.GetTotalNumberOfFreeGBytes() <<
" GBytes. " << endl;
return 0;
}
///////////////////////////////////////////////////////////////