Problematique:
Effacer tous les fichiers d'un repertoire datant de plus de XXX jours selon un filtre donne.
Bonjour,
Je bloque sur la comparaison de la date de creation du fichier.
Voici le code que j'utilise:
Avec t_Str = std::string;
Pourriez-vous avoir l'amabilite de m'aider svp ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 unsigned long DeleteFileInDir(t_Str DirPath, t_Str FileFilter) { unsigned long ErrorCode = 0; FILETIME ft; // System Time expressed as a FileTime SYSTEMTIME st; // system time GetSystemTime(&st); // gets current time SystemTimeToFileTime(&st, &ft); // converts to file time format t_Str PathWithFilter = DirPath.append(FileFilter); WIN32_FIND_DATA data; HANDLE h = FindFirstFile(PathWithFilter.c_str(), &data); BOOL bMoreFiles = (h != INVALID_HANDLE_VALUE); while (bMoreFiles) { if ((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == false && data.ftCreationTime < (ft - 20)) OutputDebugString(data.cFileName); //DeleteFile(data.cFileName); bMoreFiles = FindNextFile(h, &data); } if (GetLastError() != ERROR_NO_MORE_FILES) ErrorCode = GetLastError(); if (h != INVALID_HANDLE_VALUE) FindClose(h); return ErrorCode; }
Merci
Partager