The following will delete the files and create a log file to store the time, etc. My newer version thows exceptions to check for errors but I don't have that here at the moment. I peaced this together because I usually check the date before I delete so I may have missed a semi-colen or two. Never tried it on NT but no problems with 95 or 98.
You can copy the code below, past it in a new .cpp file, select all (Ctrl+A), then Re-format (Alt+F8).
Be carefull.
#include <afxwin.h>
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <time.h>
int main(int argc, char* argv[])
{
BOOL DirectoryNotFile;
CFileFind File; // find file object
ofstream logfile; // file object
CString csSourcePathAndFileName; // path to delete files
CString csLogPathAndFileName; // path to Log file
int NumFilesActedOn = 0; // num files deleted
int NumFilesFound = 0; // num files found
csSourcePathAndFileName == "c:\\temp\\*.jpg";
csLogPathAndFileName == "C:\\Temp\\MaintenanceLog.txt";
logfile.open(csLogPathAndFileName,ios::app); // open file for appending
time_t ltime; // get date and time
time( <ime );
logfile << "\n" << ctime(<ime); // write time to file
// find first file
BOOL bWorking = File.FindFile(csSourcePathAndFileName);
while (bWorking){ // loop while files are found
NumFilesFound = NumFilesFound+1; // increment file count
bWorking = File.FindNextFile(); // find next file
DirectoryNotFile = File.IsDirectory(); // check if file is actually a directory
if(DirectoryNotFile == FALSE){
if(DeleteFile(File.GetFilePath())){ // delete file
NumFilesActedOn = NumFilesActedOn + 1; // ++ count
}
else{
// log error
logfile << "Error Deleting: " << File.GetFilePath();
logfile << " Error " << GetLastError() << endl;
}
}
}
logfile << "Found " << NumFilesFound << "\t"; // log files found
logfile << "Deleted " << NumFilesActedOn << "\tPath " << (LPCTSTR)csSourcePathAndFileName << endl;
File.Close();
return 0;
}