简体   繁体   English

如何使用xcopy将文件复制到非现有目录?

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

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. 如果我使用mkdir,我将不得不在使用mkdir之前解压缩目录路径。 I was just wondering if its possible to use xcopy to achieve mkdir+copy at the same time. 我只是想知道是否可以使用xcopy同时实现mkdir + copy。

xcopy reference for all. 所有的xcopy参考

Thanks for the help. 谢谢您的帮助。

Try this: 试试这个:

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

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. 会做正确的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM