Xcopy in SQL

  • Hai gurus,

    I am unable to copy using xcopy

    exec master.dbo.xp_cmdshell N'xcopy D:\testing\testbat.bat D:\testing\DTS\testbat.bat < NUL:'

    exec master.dbo.xp_cmdshell N'xcopy D:\testing\testbat.bat D:\testing\DTS\testbat.bat'

    I get the following output

    Does D:\t8001.txt specify a file name

    or directory name on the target

    (F = file, D = directory)? ?

    Does D:\t8001.txt specify a file name

    or directory name on the target

    (F = file, D = directory)?

    Any ideas how to solve this. But this works in DOS promt with the query like

    Does D:\t8001.txt specify a file name

    or directory name on the target

    (F = file, D = directory)? ?

    Does D:\t8001.txt specify a file name

    or directory name on the target

    (F = file, D = directory)?

    If I give f it copies the file

    Thanks in advance

     


    Helen
    --------------------------------
    Are you a born again. He is Jehova Jirah unto me

  • Just specify the destination directory without the filename.

    EG: exec master.dbo.xp_cmdshell N'xcopy D:\testing\testbat.bat D:\testing\DTS'

     

    --------------------
    Colt 45 - the original point and click interface

  • Hai Phill,

    That worked great

     

    Thanks a lot

     


    Helen
    --------------------------------
    Are you a born again. He is Jehova Jirah unto me

  • It is worth looking at the help text for XCOPY because there are a number of switches that are extremely useful.

    I have to copy across a backup file from one server to another every night and use three switches

    /q Suppresses all XCOPY status messages (but not prompts)

    /d Only bothers to copy the file if the timestamps are different. The file is very large so this is extremely useful.

    /y Answers 'Y' to any prompts asking "Do you want to copy the file?"

    There are a load more besides that allow copying of sub-directories, whether those directories should be copied if their empty etc.

  • echo f| xcopy sourcefilename destination filename -- will also work to return the prompt for filename or directory.

  • Just an FYI, starting with Windows Server 2008 XCOPY has been flagged from depreciation. Recommended replacement is ROBOCOPY.

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

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