Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch - Delete folders

Tags:

batch-file

First of all: I'm totally new to batch.

I want to write a batch file which deletes files and folders which are min. 5 days or older. This code works perfect with all files:

FORFILES /p "C:\Users\rs\Desktop\testbatch" /s /m *.* /d -5 /c "cmd /c if not @isdir==TRUE del @path"

But my folders are still here and I don't get how to delete them too if they are min. 5 days old. Can someone please give me a hint?

Cheers

like image 607
roemel Avatar asked Oct 23 '13 07:10

roemel


2 Answers

del deletes the files, while you need to use rmdir for directories.

like image 81
mavrosxristoforos Avatar answered Oct 10 '22 20:10

mavrosxristoforos


FORFILES /p "C:\Users\rs\Desktop\testbatch" /s /m *.* /d -5 /c "cmd /c if  @isdir==TRUE  rd /s /q  @path "
like image 30
npocmaka Avatar answered Oct 10 '22 20:10

npocmaka