How to delete the N days older files with bods on Windows

Take a notepad and write below code

REM Remove files backup older than 7 days
forfiles /p “C:\backup\folder” /s /m *.* /c “cmd /c Del @path” /d -7

Where,
/p <Path> : Specifies the path from which to start the search.
/s = search sub-directories
/m = search mask
/c = set a command
This code will delete files older than 7 days, if you want to delete 15 days older file write 15 instead of 7

Then call the bat file from bods script

exec(‘cmd’, ‘C:\delete_older_File.bat’, 8);

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.