March 23, 2010 at 9:13 pm
Hi Folks
I have a table of file names that I want to loop through, and copy the physical file to another location using xp_cmdshell.
Code in my stored procedure:
set @Cmd = N'copy c:\SQLOldFiles\"' + @FileName+ '" c:\SQLNewFiles\, NO_OUTPUT'
EXEC MASTER.DBO.xp_cmdshell @Cmd
This results in The syntax of the command is incorrect. when executing the query
When I copy and paste the @Cmd string copy c:\SQLOldFiles\"TestRemainderFile.txt" c:\SQLNewFiles\
to command line, it works fine.
What am I doing wrong?
Thanks in advance
March 23, 2010 at 10:05 pm
i think the entire path+file must be in dbl quotes, not just the filename;
copy "c:\SQLOldFiles\TestRemainderFile.txt" c:\SQLNewFiles
Lowell
March 24, 2010 at 12:16 am
Hi,
Thanks for the reply.
The filename has embedded spaces in some cases, hence the double quotes around the filename only
March 24, 2010 at 1:08 am
Try this
set @Cmd = N'copy "c:\SQLOldFiles\' + @FileName+ '" "c:\SQLNewFiles\"'
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
March 24, 2010 at 1:27 am
Many many thanks!
I was starting to get into dynamic sql and char(39)'s...
Havn't tested yet, but will this also work with apostrophes in the file name, E.g. "I'll be watching.mp3"
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply