delete old folders

Microsoft Windows 2003 server - 5 users
August 5, 2009 at 17:12:57
Specs: win2k3 server, quad xeon/ 8gb
Hello,

Need a simple batch file that will do the following:

1. Check to see if there are folders older then X days in a given path.
2. If there are do action 1 if not do/goto 2
3. action 1 is to delete all folders that are more then X days old.

Thank you in advanced for your help


See More: delete old folders

Report •


#1
August 6, 2009 at 05:50:52
2. If there are do action 1 if not do/goto 2
What's this "2" you mention?

Report •

#2
August 6, 2009 at 09:59:27
Action 2 varies but its something i can handle

Report •

#3
August 7, 2009 at 10:28:57
anyone know if you can use forfiles to delete directories by date? Have it working for files but not for folders.

Report •

Related Solutions

#4
August 11, 2009 at 09:49:54
OK so I have this working so far:

ForFiles /P "PATH TO FILES" /D -7 /C "CMD /C if @ISDIR==TRUE echo RD /Q /S @FILE &RD /Q /S @FILE"

which will delete folders by the age (don't need exact math on this).

My issue now is that I need to check for the existance of folders that are more then X days old. If it finds them it will delete them if it doesn't then it GOTO :NOTFOUND (something like this).

Any suggestions?


Report •

#5
August 13, 2009 at 14:34:19
You MIGHT be able to use the errorLevel from FORFILES to see if it found anything. I say "might" because I don't have FORFILES, so I can't test its behavior.

Report •


Ask Question