Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file to delete folders older than 10 days in Windows 7

Tags:

batch-file

I want to create a batch file which should delete all subfolders of a folder which are older than 10 days, using Windows 7

Any help would be appreciated.

like image 264
nilesh Avatar asked Mar 31 '11 08:03

nilesh


People also ask

How do you automate delete files?

Setting a folder to auto-deletebutton for the folder and select Settings. From the Folder Settings screen scroll down to Automated Actions>Delete or Unshare. Check the Auto-delete this folder on a selected date checkbox and choose a date you want the folder to be deleted.

How do I delete old files using Command Prompt?

Now that Command Prompt is open, use cd to change directories to where your files are. To delete a file, use the following command: del "<filename>" . For example, to delete Test file. txt , just run del "Test File.


1 Answers

Adapted from this answer to a very similar question:

FORFILES /S /D -10 /C "cmd /c IF @isdir == TRUE rd /S /Q @path" 

You should run this command from within your d:\study folder. It will delete all subfolders which are older than 10 days.

The /S /Q after the rd makes it delete folders even if they are not empty, without prompting.

I suggest you put the above command into a .bat file, and save it as d:\study\cleanup.bat.

like image 123
Blorgbeard Avatar answered Sep 28 '22 06:09

Blorgbeard