Disclaimer:
This was not compiled or tested. Make sure the century comparison works correctly. I've forgotten if there might be a Y2K bug in the CTime library?
Using MFC, do something like this:
{
CFileFind InFiles;
CString sPathAndFile;
CString sCommand;
BOOL bMoreFiles = InFiles.FindFile( "*.*" );
CTime tRightNow = CTime::GetCurrentTime();
while ( bMoreFiles )
{
bMoreFiles = InFiles.FindNextFile();
CTime tCreationTime;
if ( Infiles.GetCreationTime( &tCreationTime ) )
{
if ( tCreationTime.GetYear() <= tRightNow.GetYear() - 2 )
{
// more comparisons for month, day, hour, minute...
cout << InFiles.GetFilePath();
sCommand.Format( "del %s", InFiles.GetFilePath() );
// comment out until you've tested!
// system( (LPSTR&) sCommand );
}
}
}
}
Hope this helps.