1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| #include <windows.h>
void mycalculTaille(char * rep, __int64 *taille)
{
WIN32_FIND_DATA FindFileData;
char path[MAX_PATH];
strcpy(path,rep);
strcat(path,"\\*.*");
HANDLE hFind = FindFirstFile(path, &FindFileData);
if (hFind==INVALID_HANDLE_VALUE)
return;
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,rep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
mycalculTaille(path, taille);
}
DWORD a = 0;
while (a != ERROR_NO_MORE_FILES)
{
if (!FindNextFile(hFind, &FindFileData))
a = GetLastError();
else
{
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,rep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
mycalculTaille(path, taille);
else
{
*taille = *taille + (FindFileData.nFileSizeHigh * ((long)MAXDWORD+1) + FindFileData.nFileSizeLow);
}
}
}
}
FindClose(hFind);
}
__int64 calculTaille(char * rep)
{
__int64 taille;
taille = 0;
mycalculTaille(rep, &taille);
return taille;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
__int64 taille = calculTaille("d:\\truc");
return 1;
} |
Partager