I'm writing this to delete PDF files that are older than two years. I have it right now so that it deletes all PDFs. It runs, but when the program finishes I get a segmentation fault. How do I fix this? Then how to I subtract 2 years from my variables st or ft?
Code:#include <iostream> #include <windows.h> /* Deletes all PDF files older than 2 years */ using namespace std; int main() { char delme[]=""; int ErrorCode; SYSTEMTIME st; FILETIME ft; LARGE_INTEGER mine, file; HANDLE hFind; WIN32_FIND_DATA FindData; GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); mine.LowPart=ft.dwLowDateTime; mine.HighPart=ft.dwHighDateTime; hFind=FindFirstFile("S:\\*.pdf", &FindData); if(hFind==INVALID_HANDLE_VALUE) { FindClose(hFind); return 0; } file.LowPart=FindData.ftCreationTime.dwLowDateTime; file.HighPart=FindData.ftCreationTime.dwHighDateTime; if(mine.QuadPart>file.QuadPart){ strcat(delme,"del S:\\"); strcat(delme,FindData.cFileName); system(delme); } while(FindNextFile(hFind, &FindData)) { ErrorCode=GetLastError(); if(ErrorCode==ERROR_NO_MORE_FILES) return 0; file.LowPart=FindData.ftCreationTime.dwLowDateTime; file.HighPart=FindData.ftCreationTime.dwHighDateTime; if(mine.QuadPart>file.QuadPart){ strcat(delme,"del S:\\"); strcat(delme,FindData.cFileName); system(delme); } } FindClose(hFind); return 0; }



LinkBack URL
About LinkBacks



CornedBee