windows 如何使用 xcopy 将文件复制到不存在的目录中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3365756/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:55:46  来源:igfitidea点击:

How to use xcopy to copy a file into a non existing directory?

windowscommand-linexcopy

提问by bits

As a part of an automated script, I am trying to do achieve something like this in windows command prompt:

作为自动化脚本的一部分,我试图在 Windows 命令提示符下实现类似的功能:

xcopy /I /Y resources\xyz\pqrs.txt %TEMP%\resources\xyz\pqrs.txt.bak

In %TEMP%, there is no resources directory.

在 %TEMP% 中,没有资源目录。

This is the interactive output, that I get:

这是交互式输出,我得到:

Does C:\Users\username\AppData\Local\Temp\resources\xyz\pqrs.txt.bak specify a file name
or directory name on the target
(F = file, D = directory)?

The whole thing is that I want to create a directory and copy file without interaction.

整件事是我想在没有交互的情况下创建一个目录和复制文件。

If I use a mkdir, I will have to extract the directory path out before using mkdir. I was just wondering if its possible to use xcopy to achieve mkdir+copy at the same time.

如果我使用 mkdir,则必须在使用 mkdir 之前提取目录路径。我只是想知道是否可以同时使用 xcopy 来实现 mkdir+copy。

xcopy referencefor all.

所有人的xcopy 参考

Thanks for the help.

谢谢您的帮助。

回答by Ricardo

Try this:

尝试这个:

echo d| xcopy /f C:\abc\file1 C:\abc\newfolder\file2

回声d| xcopy /f C:\abc\file1 C:\abc\newfolder\file2

回答by bj?rnen

If the destination path ends with a backslash it will automatically be treated as a directory:

如果目标路径以反斜杠结尾,它将自动被视为目录:

xcopy /f C:\abc\file1 C:\abc\newfolder\file2

will ask

会问

Does C:\abc\newfolder\file2 specify a file name
or directory name on the target
(F = file, D = directory)? f

but

xcopy /f C:\abc\file1 C:\abc\newfolder0\newfolder1\newfolder2\

will just do the right thing.

只会做正确的事。