Moving a File

  • Hi

    i need to move a physical file from one location to other location.for eg:i am having 1 file 1.txt in c:\test.i need to move that file to d:\test.

    will it be possible through sql server?if possible can you please provide the script to do that.

    Thanks for any quick response.

  • Build the DOS copy command string and assign it to a variable such as @Cmd, then use xp_cmdshell

    eg

    DECLARE @Cmd VARCHAR(4000)

    ... build DOS command and assign to @Cmd

    EXEC master..xp_cmdshell @Cmd

  • you could also create a SSIS package to do this, may be a bit overkill but will enable more fuctionality if needed in the future

  • - don't use xp_cmdshell ! unless there is no way around.

    - You could launch a sqlagent job to process a simple "move c:\x.txt to y:\"

    - as already stated SSIS can help you.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

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

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