使用 xcopy 将文件从多个目录复制到一个目录 [英] Using xcopy to copy files from several directories to one directory

查看:38
本文介绍了使用 xcopy 将文件从多个目录复制到一个目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 xcopy 将文件从多个目录复制到一个目录中,只使用一个 xcopy 命令?

Is it possible to use xcopy to copy files from several directories into one directory using only one xcopy command?

假设我有目录树

根源Sub1Sub2

我想将所有 .xml 文件从目录 rootSource 包括子文件夹复制到 rootDestination.我不想复制文件夹结构,只复制文件.

I want to copy all .xml files from the directory rootSource including sub folder to rootDestination. I don't want to copy the folder structure, just the files.

推荐答案

正如 DandDI 所说,你不需要 xcopy.for 语句有很大帮助.但是,你也不需要说明 dir 命令的处理结果,这个命令会更好

As DandDI said, you don't need xcopy. for statement helps much. However, you don't need to state process outcome of dir command as well, this command helps better

for /R c:source %f in (*.xml) do copy "%f" x:destination

顺便说一句,当您从批处理文件中使用它时,您需要在变量 %f 前面添加备用 % 因此您的命令行应该是;

By the way, when you use it from a batch file, you need to add spare % in front of variable %f hence your command line should be;

for /R c:source %%f in (*.xml) do copy %%f x:destination

当你在一个批次中使用它时

when you use it within a batch

  • 应该用双引号将 %f 括起来,否则复制带空格的文件名会失败

这篇关于使用 xcopy 将文件从多个目录复制到一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆