有了下面这个获取文件夹大小的函数-已在VC验证教程,不懂获取文件夹大小的函数-已在VC验证的也能装懂了,赶紧get起来装逼一下吧!
【 tulaoshi.com - 编程语言 】
//Get size of a whole dir
//return bytes
DWORD64 GetFolderSize(LPCTSTR szPath, DWORD *dwFiles, DWORD *dwFolders)
{
TCHAR szFileFilter[512];
TCHAR szFilePath[512];
HANDLE hFind = NULL;
WIN32_FIND_DATA fileinfo;
DWORD64 dwSize = 0;
strcpy(szFilePath,szPath);
strcat(szFilePath,"");
strcpy(szFileFilter,szFilePath);
strcat(szFileFilter,"*.*");
hFind = FindFirstFile(szFileFilter,&fileinfo);
do
{
if(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!strcmp(fileinfo.cFileName,".") || !strcmp(fileinfo.cFileName,".."))
{
//Do nothing for "." and ".." folders
}
else
{
TCHAR sztmp[512];
strcpy(sztmp,szFilePath);
strcat(sztmp,fileinfo.cFileName);
dwSize = dwSize + GetFolderSize(sztmp);
if(dwFolders != NULL)
{
++(*dwFolders);
}
}
}
else
{
if(dwFiles != NULL)
{
++(*dwFiles);
}
}
dwSize += fileinfo.nFileSizeLow;
}while(FindNextFile(hFind,&fileinfo));
FindClose(hFind);
return dwSize;
}
来源:http://www.tulaoshi.com/n/20160219/1625219.html
看过《获取文件夹大小的函数-已在VC验证》的人还看了以下文章 更多>>