Skip to Content
Author's profile photo Gokul Gawande

Delete files older than N days

Hi All,

Simplifying the way – How to delete the N days older files with bods(Windows Platform).

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);


Regards,

Gokul

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Can you explain what is /p / s /m in the below code to better understanding..


      /p "C:\backup\folder" /s /m *.* /c "cmd /c Del @path" /d -7


      Thanks

      Subbu

      Author's profile photo Gokul Gawande
      Gokul Gawande
      Blog Post Author

      Hi Subbarao,

      Answer for your question is :

      /p <Path> : Specifies the path from which to start the search.

      /s = search sub-directories

      /m = search mask

      /c = set a command

      Regards,

      Gokul