VS 2012: Post Build xcopy error 2

感情迁移 提交于 2019-11-30 08:14:38
Iarek Kovtunenko

Xcopy documentation says the following:

Specifying whether Destination is a file or directory If Destination does not contain an existing directory and does not end with a backslash (\), the following message appears:

Does destination specify a file name 
or directory name on the target 
(F = file, D = directory)? 

Press F if you want the file or files to be copied to a file. Press D if you want the file or files to be copied to a directory.

You can suppress this message by using the /i command-line option, which causes xcopy to assume that the destination is a directory if the source is more than one file or a directory.

You need the opposite, but there is no such switch.

The solution is proposed here: https://stackoverflow.com/a/4283533/532647.

It is suggested to prepend the xcopy command with echo f | prefix, which basically does the following: it simulates a user pressing f key when xcopy asks.

So your command should look like:

if exist $(TargetPath)
echo f | xcopy "$(TargetPath)" "C:\Users\Incubbus\Documents\Visual Studio 2010\My Libraries\z.lib" /Y

Operator | just pipes the output of echo f (== f) into xcopy command and it is read when appropriate. More information about output redirection here: http://ss64.com/nt/syntax-redirection.html.

UPDATE: As Govert points out, this hack won't work under a localized version of Windows. However, another hack will work:

xcopy D:\file.zip c:\renamedFile.zip*

Appending destination file name with an asterisk * makes xcopy not ask whether destination is a file or a directory.

Why don't you use copy instead of xcopy? copy is specifically for files so there will be no confusion.

Did you try wrapping the $(TargetPath) in quotes? The ever-so-popular-space-characters-instead-of-underscores-in-all-MS-products tend to mess things up at every corner... Dunno why those dumbos keep doing it...

Like so: if exist "$(TargetPath)"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!