计算文件夹的大小

没有直接的API函数,只有采用递归方法,下面这种判断是否是文件夹还是文件的方法与“删除文件夹”日志中的方法不一样,但是原理一样。

 

  1. LONGLONG llFolderSize; //全局变量
  2. CString OperateXML::calculateFolderSize( CString strFolderPath )
  3. {
  4.        CFileFind ff;
  5.        CString szDir = strFolderPath;
  6.        CString strSize = _T("");
  7.        if(szDir.Right(1) != "//")
  8.               szDir += "//";
  9.        
  10.        szDir += "*.*";
  11.        
  12.        BOOL res = ff.FindFile(szDir);
  13.        while(res)
  14.        {
  15.               res = ff.FindNextFile();
  16.               if(ff.IsDirectory() && !ff.IsDots())
  17.               {
  18.                      CString strFolderPath = ff.GetFilePath();
  19.                      calculateFolderSize(strFolderPath, nFileCount);
  20.               }
  21.               else if(!ff.IsDirectory() && !ff.IsDots())
  22.               {
  23.                      CString strFilePath;
  24.                      strFilePath = ff.GetFilePath();
  25.                      CFile curFile(strFilePath, CFile::modeRead);
  26.                      CFileStatus curFileStatus;
  27.                      curFile.GetStatus(curFileStatus);
  28.                      llFolderSize += curFileStatus.m_size;
  29.               }
  30.        }
  31.        ff.Close();
  32.        strSize.Format("%I64d", llFolderSize);
  33.        return strSize;
  34. }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值