没有直接的API函数,只有采用递归方法,下面这种判断是否是文件夹还是文件的方法与“删除文件夹”日志中的方法不一样,但是原理一样。
LONGLONG llFolderSize; //全局变量
CString OperateXML::calculateFolderSize( CString strFolderPath )
{
CFileFind ff;
CString szDir = strFolderPath;
CString strSize = _T("");
if(szDir.Right(1) != "//")
szDir += "//";
szDir += "*.*";
BOOL res = ff.FindFile(szDir);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())
{
CString strFolderPath = ff.GetFilePath();
calculateFolderSize(strFolderPath, nFileCount);
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
CString strFilePath;
strFilePath = ff.GetFilePath();
CFile curFile(strFilePath, CFile::modeRead);
CFileStatus curFileStatus;
curFile.GetStatus(curFileStatus);
llFolderSize += curFileStatus.m_size;
}
}
ff.Close();
strSize.Format("%I64d", llFolderSize);
return strSize;
}