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 123»»»

Delete files older than n-days via T-SQL Expand / Collapse
Author
Message
Posted Friday, April 4, 2008 11:53 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 11:12 AM
Points: 184, Visits: 1,086
Comments posted to this topic are about the item Delete files older than n-days via T-SQL

Your friendly High-Tech Janitor... :)
Post #480366
Posted Thursday, June 5, 2008 11:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 6:26 AM
Points: 7, Visits: 171
The 'Forfiles' command can do this in one line of code. I don't know why we have to re-invent the wheel here.


Post #512324
Posted Thursday, June 5, 2008 11:18 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 11:12 AM
Points: 184, Visits: 1,086
Forfiles is not included in every os by default. I needed to make sure that the code was supportable with no additional external software requirements (resource kit executables and such).

The Forfiles command would make life quite a bit simpler and it could be easily added to it and the FOR command removed...



Your friendly High-Tech Janitor... :)
Post #512338
Posted Friday, June 6, 2008 12:48 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 28, 2014 9:15 AM
Points: 4, Visits: 126
Thanks for the script.
Months ago I was looking for a scritp like this one with an additional feature: recursively delete old files in the selected folder an sub-folders.
I suppose it is difficault to deal with sub-folders at any level using T-SQL and finally I use an external exe program written in C# (deleteold.exe from codeproject).
Anyway, I would prefere this functionality in T-SQL
Regards
Post #512710
Posted Wednesday, June 11, 2008 9:09 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 17, 2013 7:29 AM
Points: 100, Visits: 49
Just curiuos if anyone is using this? I'm planning to implement this at a disaster recovery site. On our live SQL Server we back up the db and ftp it to another location. I figure that I can run this as a job at the DR site to delete the old backups.
Post #515272
Posted Wednesday, June 11, 2008 10:04 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 11:12 AM
Points: 184, Visits: 1,086
The code presented is actually about six months older than the date on it - I've been using this method on around 150 servers since it's inception with no issues.



Edit:

FWIW, you can add a PRINT @DynDelete and if you schedule the code through SQLAgent you'll have the delete command output so you can record what is being deleted by having the job step append its output to a file. [My production version of this logs the deletes to a table]


Your friendly High-Tech Janitor... :)
Post #515327
Posted Wednesday, June 11, 2008 10:13 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 17, 2013 7:29 AM
Points: 100, Visits: 49
thanks
Post #515337
Posted Tuesday, July 29, 2008 3:56 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 5:31 AM
Points: 139, Visits: 4,617

If you want to use SQL instead of other applications and you're using SQL Server 2005, why you don't use the extended procedure xp_delete_file?

Personally I feel it quite restricted and I still use a delete command line that I create for myself when I was using SQL Server 2000.
Post #542464
Posted Tuesday, August 5, 2008 12:51 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, July 12, 2014 9:14 AM
Points: 30, Visits: 287
I'm trying it and getting all kinds of incorrect syntax error when parsing it.
Post #547027
Posted Tuesday, August 5, 2008 12:56 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 11:12 AM
Points: 184, Visits: 1,086
It might be the extra characters that are 'added' to the script when posted.


Your friendly High-Tech Janitor... :)
Post #547029
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse