zoukankan      html  css  js  c++  java
  • 获取文件或是文件夹的大小和占用空间

     1 //Get size of a whole dir
     2 //return bytes
     3 DWORD64 GetFolderSize(LPCTSTR szPath, DWORD *dwFiles, DWORD *dwFolders)
     4 {
     5  TCHAR szFileFilter[512];
     6  TCHAR szFilePath[512];
     7  HANDLE hFind = NULL;
     8  WIN32_FIND_DATA fileinfo;
     9  DWORD64    dwSize = 0;
    10  
    11  strcpy(szFilePath,szPath);
    12  strcat(szFilePath,"");
    13  strcpy(szFileFilter,szFilePath);
    14  strcat(szFileFilter,"*.*");
    15  
    16  hFind = FindFirstFile(szFileFilter,&fileinfo);
    17  do
    18  {
    19   if(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    20   {
    21    if (!strcmp(fileinfo.cFileName,".") || !strcmp(fileinfo.cFileName,".."))
    22    {
    23     //Do nothing for "." and ".." folders
    24    }
    25    else
    26    {
    27     TCHAR sztmp[512];
    28     strcpy(sztmp,szFilePath);
    29     strcat(sztmp,fileinfo.cFileName);
    30     dwSize = dwSize + GetFolderSize(sztmp);
    31     if(dwFolders != NULL)
    32     {
    33      ++(*dwFolders);
    34     }
    35    }
    36   }
    37   else
    38   {
    39    if(dwFiles != NULL)
    40    {
    41     ++(*dwFiles);
    42    }
    43   }
    44  
    45   dwSize += fileinfo.nFileSizeLow;
    46  
    47  }while(FindNextFile(hFind,&fileinfo));
    48  
    49  FindClose(hFind);
    50  return dwSize;
    51 }
  • 相关阅读:
    xml的建模
    P1341 无序字母对
    P1330 封锁阳光大学
    P2661 信息传递
    P1312 Mayan游戏
    P1514 引水入城
    C. Sad powers
    P1195 口袋的天空
    P1821 [USACO07FEB]银牛派对Silver Cow Party
    P1396 营救
  • 原文地址:https://www.cnblogs.com/chechen/p/5145638.html
Copyright © 2011-2022 走看看