SQLServerCentral.com / SQL Server 2008 / T-SQL (SS2K8) / Job to delete folders older than X days old ? / Latest PostsInstantForum.NET v2.9.0SQLServerCentral.comhttp://www.sqlservercentral.com/Forums/notifications@sqlservercentral.comTue, 31 Mar 2015 16:39:16 GMT20RE: Job to delete folders older than X days old ?http://www.sqlservercentral.com/Forums/Topic1538824-392-1.aspx[quote][b]homebrew01 (2/6/2014)[/b][hr]I run this as a SQL scheduled job on my Windows 2003 server:[font="Courier New"][b]ForFiles /P D:\objectscripts /D -180 /C "CMD /C if @ISDIR==TRUE echo RD /Q /S @FILE &RD /Q /S @FILE[/b]"[/font]It deletes the folders in D:\objectscripts older than 180 days. Not sure about the syntax, I just found it the other day on someone's website. Test it first in a non critical area.[/quote]Nice find.Thu, 06 Feb 2014 20:56:20 GMTSQLRNNRRE: Job to delete folders older than X days old ?http://www.sqlservercentral.com/Forums/Topic1538824-392-1.aspxI run this as a SQL scheduled job on my Windows 2003 server:[font="Courier New"][b]ForFiles /P D:\objectscripts /D -180 /C "CMD /C if @ISDIR==TRUE echo RD /Q /S @FILE &RD /Q /S @FILE[/b]"[/font]It deletes the folders in D:\objectscripts older than 180 days. Not sure about the syntax, I just found it the other day on someone's website. Test it first in a non critical area.Thu, 06 Feb 2014 14:41:02 GMThomebrew01Job to delete folders older than X days old ?http://www.sqlservercentral.com/Forums/Topic1538824-392-1.aspxHiI wanted to run a job nightly that would delete folders within a folder that where older than 3 days oldfor example c:\output has 2 folders (c:\output\folder1 and c:\output\folder2) I don't care whats in them only if folder1 or folder2 is older than 3 days delete the entre folderjust leave c:\output Thanks in Advance JoeThu, 06 Feb 2014 13:13:32 GMTjbalbo