WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

File Operations

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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
File Created: 2002:09:05:13:50:00
Last Updated: 2002:09:05:13:50:00