Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Job to delete folders older than X days old ? Expand / Collapse
Author
Message
Posted Thursday, February 6, 2014 1:13 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, July 23, 2014 2:00 PM
Points: 295, Visits: 488
Hi

I wanted to run a job nightly that would delete folders within a folder that where older than 3 days old

for 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 folder
just leave c:\output

Thanks in Advance
Joe
Post #1538824
Posted Thursday, February 6, 2014 2:41 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Saturday, July 26, 2014 8:10 PM
Points: 2,826, Visits: 8,463
I run this as a SQL scheduled job on my Windows 2003 server:

ForFiles /P D:\objectscripts /D -180 /C "CMD /C if @ISDIR==TRUE echo RD /Q /S @FILE &RD /Q /S @FILE"

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.



Post #1538877
Posted Thursday, February 6, 2014 8:56 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 4:09 PM
Points: 21,252, Visits: 14,960
homebrew01 (2/6/2014)
I run this as a SQL scheduled job on my Windows 2003 server:

ForFiles /P D:\objectscripts /D -180 /C "CMD /C if @ISDIR==TRUE echo RD /Q /S @FILE &RD /Q /S @FILE"

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.


Nice find.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1538985
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse