码迷,mamicode.com
首页 > 其他好文 > 详细

获取磁盘总空间和剩余空间

时间:2018-03-12 16:58:27      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:call   font   tar   ring   data   nbsp   imp   space   proc   

BOOL MyLocalMacIP::GetSpaceInfo(CString &totalspace, CString &usedspace)  
{  
    long long total = 0;  
    long long used = 0;  
  
    ::vector<CString> drivernames;  
    int drivernum = 0;  
  
    CString str;  
  
    DWORD size = ::GetLogicalDriveStringsA(0, NULL);  
    if (0 != size)  
    {  
        HANDLE heap = ::GetProcessHeap();  
        LPSTR lp = (LPSTR)HeapAlloc(heap, HEAP_ZERO_MEMORY, size*sizeof(TCHAR));  
        ::GetLogicalDriveStringsA(size*sizeof(TCHAR), lp);  
  
        while(0 != *lp )  
        {  
            /* we don‘t need C:*/  
            int str_num = strcmp((char*)lp, ("C:\\"));  
            if (str_num == 0)  
            {  
                lp = strchr(lp, 0)+1;  
                continue;  
            }  
            wchar_t* lp_buffer = conversion.CharToWchar(lp);  
            UINT res = ::GetDriveTypeW(lp_buffer);  
            if(DRIVE_FIXED == res)  
            {  
                CString str = lp;  
                drivernames.push_back(str);  
                drivernum++;  
            }  
            delete []lp_buffer;  
            lp = strchr(lp, 0)+1;  
      
        }  
  
    }  
    ULARGE_INTEGER FreeSpace, CallSpace, TotalSpace;  
      
    for (int i = 0; i < drivernum; i++)  
    {  
        ::GetDiskFreeSpaceEx(drivernames[i], &FreeSpace, &CallSpace, &TotalSpace);  
         total += CallSpace.QuadPart;  
         used += FreeSpace.QuadPart;  
    }  
  
    string stotal = conversion.IntToString(total);  
    string sused = conversion.IntToString(used);  
    totalspace = CString(stotal.c_str());  
    usedspace = CString(sused.c_str());  
  
    return TRUE;  
} 

  

  1. BOOL MyLocalMacIP::GetSpaceInfo(CString &totalspace, CString &usedspace)  
  2. {  
  3.     long long total = 0;  
  4.     long long used = 0;  
  5.   
  6.     ::vector<CString> drivernames;  
  7.     int drivernum = 0;  
  8.   
  9.     CString str;  
  10.   
  11.     DWORD size = ::GetLogicalDriveStringsA(0, NULL);  
  12.     if (0 != size)  
  13.     {  
  14.         HANDLE heap = ::GetProcessHeap();  
  15.         LPSTR lp = (LPSTR)HeapAlloc(heap, HEAP_ZERO_MEMORY, size*sizeof(TCHAR));  
  16.         ::GetLogicalDriveStringsA(size*sizeof(TCHAR), lp);  
  17.   
  18.         while(0 != *lp )  
  19.         {  
  20.             /* we don‘t need C:*/  
  21.             int str_num = strcmp((char*)lp, ("C:\\"));  
  22.             if (str_num == 0)  
  23.             {  
  24.                 lp = strchr(lp, 0)+1;  
  25.                 continue;  
  26.             }  
  27.             wchar_t* lp_buffer = conversion.CharToWchar(lp);  
  28.             UINT res = ::GetDriveTypeW(lp_buffer);  
  29.             if(DRIVE_FIXED == res)  
  30.             {  
  31.                 CString str = lp;  
  32.                 drivernames.push_back(str);  
  33.                 drivernum++;  
  34.             }  
  35.             delete []lp_buffer;  
  36.             lp = strchr(lp, 0)+1;  
  37.       
  38.         }  
  39.   
  40.     }  
  41.     ULARGE_INTEGER FreeSpace, CallSpace, TotalSpace;  
  42.       
  43.     for (int i = 0; i < drivernum; i++)  
  44.     {  
  45.         ::GetDiskFreeSpaceEx(drivernames[i], &FreeSpace, &CallSpace, &TotalSpace);  
  46.          total += CallSpace.QuadPart;  
  47.          used += FreeSpace.QuadPart;  
  48.     }  
  49.   
  50.     string stotal = conversion.IntToString(total);  
  51.     string sused = conversion.IntToString(used);  
  52.     totalspace = CString(stotal.c_str());  
  53.     usedspace = CString(sused.c_str());  
  54.   
  55.     return TRUE;  

获取磁盘总空间和剩余空间

标签:call   font   tar   ring   data   nbsp   imp   space   proc   

原文地址:https://www.cnblogs.com/qingtian224/p/8549267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!