Solved Batch file to delete folders older than a specified age

October 6, 2012 at 23:28:54
Specs: Windows 7
Hi,

I have a script that automatically backs up mobile devices to a computer every night that is run by Task Scheduler.

Now, I need a script or batch file that can also be run via Task Scheduler that will automatically go through the backup directory and delete folders (and the contents within that folder) older than a specified age (probably 7 days old).

I am fairly new, and just need a script that I can have run automatically so that I don't keep getting a huge backlog of old backup folders.

Thank you!

-David


See More: Batch file to delete folders older than a specified age

Report •

#1
October 6, 2012 at 23:29:58
My date format is MM-DD-YY

Report •

#2
October 7, 2012 at 03:28:04
Post a few lines of the output of this.

:: ===== script starts here ===============
::
:: older.bat 2012-10-07 17:25:37.89
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b') do (
echo %%~Ta
)
goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

#3
October 7, 2012 at 07:30:14
✔ Best Answer
forfiles /p c:\backups /d -7 /c "cmd /c if @isdir==TRUE rd /s /q @path"

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
October 7, 2012 at 08:45:05
Hey Mechanix2Go...here is the info from your script:

09/30/2012 12:10 PM
09/28/2012 11:47 AM
10/07/2012 08:42 AM

Razor - thank you! I will give that a try


Report •

#5
October 7, 2012 at 08:47:36
Razor - that did it!! Thank you!!!

Report •

Ask Question