这看起来非常简单,也许我只是忽略了适当的标志,但是我如何在一个命令中将一个文件从一个目录复制到另一个目录并在目标目录中重命名它呢?这是我的命令:

if exist "bin\development\whee.config.example"
  if not exist "TestConnectionExternal\bin\Debug\whee.config"
    xcopy "bin\development\whee.config.example"
          "TestConnectionExternal\bin\Debug\whee.config"

它每次都会提示我以下内容:

TestConnectionExternal \ bin \调试\哟。配置指定文件名 或目标上的目录名(F =文件,D =目录)?

我想压制这个提示;答案总是F。


当前回答

在目标路径的末尾放置星号(*),跳过D和F的争议。

例子:

xcopy "compressedOutput.xml" ../../执行 脚本/ APIAutomation /图书馆/ rerunlastfailedbuild.xml *”

其他回答

因为您实际上并没有更改文件名,所以可以从目标文件中取出文件名,这样就不会有问题了。

xcopy bin\development\whee.config.example TestConnectionExternal\bin\Debug\  /Y

当目标目录保证存在时,当源可能同样是一个文件或目录时,这种方法工作得很好。

Xcopy将允许您将单个文件复制到指定的文件夹中,只是不允许您定义目标名称。如果需要目标名称,只需在复制之前重命名即可。

任“bin \开发\ whee.config。“whee.config例子

xcopy /R/Y "bin\development\whee.config" “TestConnectionExternal \ bin \调试\”

我有一个类似的问题,robocopy和xcopy都没有帮助,因为我想压制注释并使用不同的目标文件名。我发现

type filename.txt > destfolder\destfilename.txt

按我的要求工作。

我使用

echo f | xcopy /f /y srcfile destfile

为了绕过它。

xcopy src dest /I

REM这假设dest是一个文件夹,如果它不存在,将创建它