且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在sqlserver2008中使用xp_cmdshell替换文件?

更新时间:2023-10-02 21:55:52

删除 + 字符。您的声明正在尝试将这两个文件复制到一个新文件中,该文件名为 Test1.docx 。您可以在命令窗口中键入 copy /?来检查确切的语法。
Remove the + character. Your statement is trying to copy those two files to a new one, which will be named Test1.docx. You can check the exact syntax by typing copy /? in a command window.


快速查看您的评论,@ newPath正在被注释掉。

Having a quick look at your comment, @newPath is being commented out.
SET @newFlieName=@DestLink--+@newPath



命令的输出类似于:


The output of the command would be something like:

COPY /Y  "C:\New\Test1.docx"  /B "D:\New\"



这会将位置 C:\New \ 中的文件 Test1.docx 复制到目的地 D:\ Neww \\ 使用相同的文件名 Test1.docx



请阅读: http://ss64.com/nt/copy.html [ ^ ],我发现这是命令行参考的一个很好的来源。



另外你应该知道安全问题 使用xp_cmdshell时。

http:// blogs.msdn.com/b/sqlsecurity/archive/2008/01/10/xp-cmdshell.aspx [ ^ ]


This will copy the file Test1.docx in location C:\New\ to destination D:\New\ with the same file name Test1.docx.

Please read: http://ss64.com/nt/copy.html[^], I find this a good source for command line references.

Also you should be aware of the security issues when using xp_cmdshell.
http://blogs.msdn.com/b/sqlsecurity/archive/2008/01/10/xp-cmdshell.aspx[^]