磁盘空间大小管理

发布时间:2024年01月20日

#if _MSC_VER > 1000
#pragma once
#endif

#include <windows.h>

class CHardDiskManager
{
public:
CHardDiskManager();
virtual ~CHardDiskManager();

bool CheckFreeSpace(LPCTSTR lpDirectoryName);

DWORD64 GetFreeBytesAvailable(void);
DWORD64 GetTotalNumberOfBytes(void);
DWORD64 GetTotalNumberOfFreeBytes(void);

double GetFreeGBytesAvailable(void);
double GetTotalNumberOfGBytes(void);
double GetTotalNumberOfFreeGBytes(void);
private:
ULARGE_INTEGER m_uliFreeBytesAvailable;
ULARGE_INTEGER m_uliTotalNumberOfBytes;
ULARGE_INTEGER m_uliTotalNumberOfFreeBytes;
};

// HardDiskManager.cpp
#include “stdafx.h”
#include <afxwin.h>
#include “HardDiskManager.h”

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)/1073741824 );
}
double CHardDiskManager::GetTotalNumberOfGBytes(void)
{
return (double)( (signed __int64)(m_uliTotalNumberOfBytes.QuadPart)/1073741824 );
}

double CHardDiskManager::GetTotalNumberOfFreeGBytes(void)
{
return (double)( (signed __int64)(m_uliTotalNumberOfFreeBytes.QuadPart)/1073741824 );
}

文章来源:https://blog.csdn.net/u011637657/article/details/135718638
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。