Windows将子文件夹中的文件批量复制到一个文件夹 [英] Windows batch copy files from subfolders to one folder
问题描述
我曾尝试制作批处理脚本,将位于D:\ images(此处随机命名为子文件夹)中的所有* .tif文件复制到d:\ all.
I had tried to make batch script that copies all *.tif files located in D:\images(random named subfolders here) to d:\all.
xcopy D:\Downloads\*.TIF D:\temp\ /s
可行,但它会复制所有文件夹树.我尝试使用其他键,但是它不起作用. 感谢您的帮助!
works, but it copies with all folder tree. I tried to use other keys, but its dont works. Thanks for help!
推荐答案
FOR
是您的朋友.阅读/R
选项和%~nx
变量替换上的HELP FOR
;然后尝试这个非常简单的代码.
FOR
is your friend. Read HELP FOR
on the /R
option and the %~nx
variable substitution; and then try this very simple code.
pushd d:\downloads
for /r %%a in (*.tif) do (
echo COPY "%%a" "d:\temp\%%~nxa"
)
popd
仔细观察结果,然后删除ECHO
命令.
watch carefully the results and then remove the ECHO
command.
您将不得不优化代码以应对错误,重复的名称,边缘情况,带有保留字符的名称,竞争条件,宇宙事件...
You will have to refine the code to cope with errors, duplicate names, edge cases, names with reserved characters, race conditions, cosmic events...
这篇关于Windows将子文件夹中的文件批量复制到一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!