如果指定目录不存在,XCOPY 切换到创建指定目录吗?
我在构建后事件中使用 XCOPY 将已编译的 DLL 从其输出文件夹复制到主应用程序的输出文件夹。 DLL 被复制到主应用程序输出文件夹中的“Modules”子文件夹,如下所示:
xcopy "$(TargetPath)" "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\"
如果 Modules 文件夹存在,该命令可以正常工作,但我在测试过程中发现,如果该文件夹不存在,则 XCOPY 不会创建它,命令失败。
如果文件夹不存在,是否有 XCOPY 开关会导致创建该文件夹?如果没有,我会在构建后事件中添加什么来创建文件夹(如果该文件夹不存在)?感谢您的帮助。
I am using XCOPY in a post-build event to copy compiled DLLs from their output folders to the main app's output folder. The DLLs are being copied to a "Modules" subfolder in the main app output folder, like this:
xcopy "$(TargetPath)" "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\"
The command works fine if the Modules folder exists, but I have discovered during testing that if the folder doesn't exist, XCOPY doesn't create it, and the command fails.
Is there an XCOPY switch that will cause the folder to be created if it doesn't exist? If not, what would I add to my post-build event to create the folder if it doesn't exist? Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用“/I”的答案是有效的,但有一点技巧 - 在目标中,您必须以字符 \ 结尾,以告诉 xcopy 目标是目录而不是文件!
示例:
不起作用并返回代码 2,但是这个:
我的示例中使用的命令行参数:
/F - 显示完整源代码和代码目标文件名
/R - 这将覆盖只读文件
/Y - 禁止提示覆盖现有文件
/I - 假设目标是目录(但必须以 \ 结尾)
Answer to use "/I" is working but with little trick - in target you must end with character \ to tell xcopy that target is directory and not file!
Example:
does not work and return code 2, but this one:
Command line arguments used in my sample:
/F - Displays full source & target file names
/R - This will overwrite read-only files
/Y - Suppresses prompting to overwrite an existing file(s)
/I - Assumes that destination is directory (but must ends with \)
我在命令行上尝试了此操作
,并且目标目录已正确创建。
如果没有,您可以使用
mkdir
命令创建目标目录,并启用cmd
的命令扩展,例如('/x' 启用命令扩展,以防它们未启用您系统上的默认设置,我不太熟悉
cmd
),请使用它
来获取更多信息:)
I tried this on the command line using
and the target directory was properly created.
If not you can create the target dir using the
mkdir
command withcmd
's command extensions enabled like('/x' enables command extensions in case they're not enabled by default on your system, I'm not that familiar with
cmd
)use
for further information :)
我讨厌 PostBuild 步骤,它允许在构建工具的权限之外发生太多事情。我认为最好让 MSBuild 管理复制过程并进行更新。您可以像这样编辑 .csproj 文件:
I hate the PostBuild step, it allows for too much stuff to happen outside of the build tool's purview. I believe that its better to let MSBuild manage the copy process, and do the updating. You can edit the .csproj file like this:
将 /i 与 xcopy 一起使用,如果目录不存在,它将创建该目录
为你。
Use the /i with xcopy and if the directory doesn't exist it will create the directory
for you.
您可以使用 robocopy:
You could use robocopy:
简单简短的回答是这样的:
Simple short answer is this:
只需输入引号斜杠分隔符 "/" 并添加到最终目标 2 个反斜杠 "\\"
它将创建新文件夹来复制和复制需要的文件(- s)。
Simply type in quotes slash delimiter "/" and add to final destination 2 back-slashes "\\"
It's will be create New folders to copy and copy need file(-s).
我在命令上尝试过这个。它对我有用。
I tried this on the command.it is working for me.
尝试 /E
要获取完整的选项列表: xcopy /?
Try /E
To get a full list of options: xcopy /?
要在复制过程中使用 xcopy 命令创建文件夹,您可以包含 /I 开关。如果正在复制多个文件或目标不存在,此开关告诉 xcopy 假设目标是一个目录。如果目标不存在,则会将其创建为目录。
以下是将 xcopy 与 /I 开关一起使用的基本语法:
To use xcopy command to create folders during the copying process, you can include the /I switch. This switch tells xcopy to assume that the destination is a directory if multiple files are being copied or if the destination does not exist. If the destination does not exist, it will be created as a directory.
Here's the basic syntax for using xcopy with the /I switch: