zoukankan      html  css  js  c++  java
  • 获取磁盘总空间和剩余空间

    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;  
  • 相关阅读:
    js通过class获取元素时的兼容性解决方案
    html5的八大特性
    typeof与instanceof的区别
    evel()与JSON.parset()的区别
    apt-get出现的问题
    Linux下开启计划任务日志
    ls
    win10自带IE上不了网的解决办法
    crontab -e文件存放路径
    Linux系统下面crontab选择默认编译器
  • 原文地址:https://www.cnblogs.com/qingtian224/p/8549267.html
Copyright © 2011-2022 走看看