Computing.Net > Forums > Programming > Delete Files in a directory older than X days

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete Files in a directory older than X days

Reply to Message Icon

Name: amiller
Date: August 5, 2009 at 08:54:59 Pacific
OS: Windows XP
Subcategory: Batch
Tags: Batch file, delete files
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: August 6, 2009 at 05:54:10 Pacific
Reply:

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.


0

Response Number 2
Name: amiller
Date: August 6, 2009 at 07:46:31 Pacific
Reply:

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.


0

Response Number 3
Name: Razor2.3
Date: August 6, 2009 at 08:12:11 Pacific
Reply:

amiller: it didnt delete all .zip files. kept the most recent one.
Yes, that's what excluding means.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Delete Files in a directory older than X days

Batch file to delete files in a dir www.computing.net/answers/programming/batch-file-to-delete-files-in-a-dir/14599.html

Count files in a directory www.computing.net/answers/programming/count-files-in-a-directory/12308.html

count no of files in a directory www.computing.net/answers/programming/count-no-of-files-in-a-directory/18316.html