Reputation: 1
I am trying to use a batch file to delete .rar files from a certain folder which are older than 30 days. However the batch file I have right now deletes any file older than 30 days, I want to limit this just to .rar files. My code is below.
REM *******************************************************************
REM Deleting database backups older than 30 days.
@echo off
@Echo Deleting database backups older than 30 days...
rem echo y|forfiles /p C:\Batch\Archives\*.rar /d -30 /c "cmd /c del @path"
pause
EXIT
Upvotes: 0
Views: 733
Reputation: 7880
If you look at forfiles
help, you will see that the /P
parameter is just for the path. You need to use the /M
parameter for a file mask. So you should use this:
forfiles /p C:\Batch\Archives /m *.rar /d -30 /c "cmd /c del @path"
In my case, there's no need to echo an 'y' to confirm. But if in your case del
is asking for confirmation, just use its /Q
parameter.
On a side not, there's no need to use @
again after using @echo off
. You either use @echo off
in the first line or place a @
before each line, doing both is not necessary and makes your file uglier.
Furthermore, I would place the @echo off
before those REM
s so they are not displayed. If you want to show those messages, just use echo
. The final EXIT
is also not needed.
Upvotes: 1