Deleting an arbitrary filetype without using x_cmdshell?

  • 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

  • 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

  • By any chance would you still have the code lying around? Thanks.

  • 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

  • Thanks. freinds.;-)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply