August 17, 2009 at 1:15 pm
Using CLR or T-SQL, is there a way of deleting an arbitrary file type in SQL based on date, without using xp_cmdshell? xp_delete_file is very limited in the types of files it will delete (besides being officially unsupported).
Thanks
August 17, 2009 at 2:05 pm
TSQL wise I think that xp_cmdshell is really the best way.
However, I have done this in SQLCLR, the assembly had the permission set of EXTERNAL_ACCESS if I remember. I'm having to work from memory here, but I used the system.io.directoryinfo to get the list of files using the search pattern (*.txt and such). Then taking each file as a system.io.fileinfo and deleting them one by one. There may be a better way, but that is how I did it. I also added some directories that it would NEVER allow to delete any files:
C:\WINDOWS
C:\WINNT
C:\PROGRAM FILES
C:\PROGRAM FILES(X86)
There were a few more but I can't remember clearly..
Thats how I did it..
CEWII
August 18, 2009 at 11:59 am
By any chance would you still have the code lying around? Thanks.
August 18, 2009 at 8:55 pm
From a previous employer, they own it, but that is how I did it before..
I have been meaning to rewrite them and put them up on CodePlex..
CEWII
August 24, 2009 at 11:50 pm
Thanks. freinds.;-)
-Bunk-beds:-P
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply