取得目录和取得操作系统盘符以及获取系统盘可用空间

1.取得当前目录

[cpp]  view plain  copy
  1. char        szModulePath [_MAX_PATH];   /* Path of Module */      
  2. // Get current module handle  
  3.     HMODULE module = GetModuleHandle(0);  
  4.     // Get current file path  
  5.     GetModuleFileName(module, szModulePath, sizeof(szModulePath));  
  6.     CString strPath = szModulePath;  
  7.     strPath = strPath.Left(strPath.ReverseFind(_T('//')));  
  8.     lstrcpy(szModulePath, strPath.GetBuffer(strPath.GetLength()));  

 

2.取得操作系统盘符

[cpp]  view plain  copy
  1. TCHAR sysDir[128];  
  2. GetSystemDirectory(sysDir, 128 * sizeof(TCHAR));  
  3. CString sysDisk = sysDir[0];  
  4. sysDisk.MakeUpper();  

3.取得操作系统盘可用空间的情况


// 判断系统磁盘可用空间的情况。返回可用空间大小情况: TRUE 大于1GB,FALSE 小于1GB。
 BOOL CheckSystemDiskFreeSpace( )
{
TCHAR sysDir[128];  
GetSystemDirectory(sysDir, 128 * sizeof(TCHAR));  


BOOL bret;
ULONGLONG ullMaxSpace = 0;


TCHAR szRootPath[] = { TCHAR('A'), ':', '\\', 0 };//带根目录标记的磁盘符号
szRootPath[0] = sysDir[0];
DWORD dwSectorsPerCluster = 0;//每簇中扇区数
DWORD dwBytesPerSector = 0;//每扇区中字节数
DWORD dwFreeClusters = 0;//剩余簇数
DWORD dwTotalClusters = 0;//总簇数
if (GetDiskFreeSpace(szRootPath, &dwSectorsPerCluster, &dwBytesPerSector,
&dwFreeClusters, &dwTotalClusters))
{
ullMaxSpace = ULONGLONG(dwFreeClusters)*ULONGLONG(dwSectorsPerCluster)*ULONGLONG(dwBytesPerSector);
if (ullMaxSpace > 1024*1024*1024)
{
return TRUE;
}
}
return FALSE;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值