Skip to content
May 3, 2012 / doganay

WINDOWS BATCH FILE TO DELETE FILES OLDER THAN N DAYS

To delete files older than NUM_OF_DAYS  days:

forfiles /p "<directory>" /m <file_wildcard> /d -<NUM_OF_DAYS> /c "cmd /c del @path"

– use *.* wildcard for  all files

This one is the recursive version, deletes files in sub-directories matching criteria.

forfiles /p "<directory>" /s /m <file_wildcard> /d -<NUM_OF_DAYS> /c "cmd /c del @path"
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: