Delete Temp Files Older Than....
Keywords: FileDelete temp delete file files older than
Question:
I am looking for a way to delete temp files (\temp\*.tmp) that are older than 2 days. Is this possible with Winbatch, and does anyone have an example of working code that will accomplish this - no need re-inventing the wheel if it has already been done.Answer:
Here is some sample code that should get you started.CurrDay = TimeYmdHms ( ) TempFiles = FileItemize ("c:\temp\*.tmp")) For FileNum = 1 to ItemCount (TempFiles, @TAB) CurrFile = ItemExtract (FileNum, TempFiles, @TAB) CurrFileDate = FileTimeGetEx (StrCat ("c:\temp\", CurrFile),2) If TimeDiffDays (CurrDay, CurrFileDate) > 2 Then FileDelete (StrCat ("c:\temp\", CurrFile)) EndIf Next
Article ID: W15146