Create/delete files on SQL Server

  • I have found several samples for how can i use SQL-DMO to make a backup or restore a file, and so far i´ve managed to do what i need.

    However, how can i (from the client PC):

    • Delete a file on the server?
    • Create/delete a directory on the server?

    I am assuming that i don´t know the server directory structure.

    Thanks

    Carlos Crespo

     

  • You can figure out the directory structure AND create/delete files and directories by using a series of xp_cmdshell commands in Query Analyzer, as long as you have admin priviliges in SQL Server. Then use good old DOS commands.

    master..xp_cmdshell 'dir c:\' --see files and directories

    master..xp_cmdshell 'md c:\myDirectory' --create 'mydirectory'

    master..xp_cmdshell 'rd c:\myDirectory' --delete 'mydirectory'

    You get the idea.


    Glen

Viewing 2 posts - 1 through 1 (of 1 total)

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