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;
} |
Partager