Method 1: Use the CFileFind class to recuriate the size of each file and then seek
CFILEFIND FF;
CString Szdir = STRDIR;
IF (szdir.right (1)! = _t ("//")))))
{
SZDIR = _t ("//");
}
SZDIR = _t ("*. *");
Bool res = ff.findfile (szdir);
While (res)
{
Res = ff.findnextfile ();
IF (ff.isdirectory () &&! f.isdots ())
{
Browsedir (ff.getfilepath ());
}
Else if (! ff.isdirectory () &&! f.isdots ())
{
CFILESTATUS RSTATUS;
IF (cfile :: getStatus (ff.getfilepath (), rtatus))
{
m_size = rstatus.m_size;
}
}
}
ff.close ();
Method 2: API function FineFirstFile recursive, this method returns to DWORD64 type double word can be converted to strings with _i64toa () function
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,". ")))
{
// 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;
}