Delete Files in a directory older than X days

August 5, 2009 at 08:54:59
Specs: Windows XP
I have been using a batch file to delete .zip files in a directory that are older than 2 days old. It has been working very well. However, I would like to modify it so it will delete files older than 5 days old. I really don't understand what this batch file is saying, all I know is that it is working. Could someone help me read this batch file and change it to delete files older than 5 days?

setlocal enabledelayedexpansion
set ftsw=Y
for /f "tokens=* delims=*" %%v in ('dir /tw /o-d /b /s C:\DBBackup\*Backup.zip') do (
if !ftsw!==N del "%%v"
call set ftsw=N
)
exit


See More: Delete Files in a directory older than X days

Report •


#1
August 6, 2009 at 05:54:10
I have been using a batch file to delete .zip files in a directory that are older than 2 days old.
No, it doesn't. It deletes every *Backup.zip, excluding the most current file.

Report •

#2
August 6, 2009 at 07:46:31
I just tested it, it didnt delete all .zip files. kept the most recent one. seems to work for me. I just wish i could understand what the code means. Thanks for your help anyways.

Report •

#3
August 6, 2009 at 08:12:11
amiller: it didnt delete all .zip files. kept the most recent one.
Yes, that's what excluding means.

Report •

Related Solutions


Ask Question