Windows 将文件从子文件夹批量复制到一个文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11720681/
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
Windows batch copy files from subfolders to one folder
提问by Sergii Rechmp
I had tried to make batch script that copies all *.tif files located in D:\images(random named subfolders here) to d:\all.
我曾尝试制作将位于 D:\images(此处为随机命名的子文件夹)中的所有 *.tif 文件复制到 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!
有效,但它与所有文件夹树一起复制。我尝试使用其他键,但它不起作用。感谢帮助!
回答by PA.
FOR
is your friend. Read HELP FOR
on the /R
option and the %~nx
variable substitution; and then try this very simple code.
FOR
是你的朋友。阅读HELP FOR
的/R
选项和%~nx
变量替换; 然后试试这个非常简单的代码。
pushd d:\downloads
for /r %%a in (*.tif) do (
echo COPY "%%a" "d:\temp\%%~nxa"
)
popd
watch carefully the results and then remove the ECHO
command.
仔细观察结果,然后删除ECHO
命令。
You will have to refine the code to cope with errors, duplicate names, edge cases, names with reserved characters, race conditions, cosmic events...
您将不得不改进代码以处理错误、重复名称、边缘情况、带有保留字符的名称、竞争条件、宇宙事件......
回答by Sham Yemul
Searched files using windows file explorer for e.g. *.gif , I got files in search window, used Edit=>Select All , copy and then pasted to desired folder. This copied all the gif files in all sub directories to single folder. For large number of files, it sometimes hangs/not responding, but otherwise works ok.
使用 Windows 文件资源管理器搜索文件,例如 *.gif ,我在搜索窗口中找到文件,使用 Edit=>Select All ,复制然后粘贴到所需的文件夹。这将所有子目录中的所有 gif 文件复制到单个文件夹。对于大量文件,它有时会挂起/不响应,但其他工作正常。
回答by Stur
pushd D:\Source
for /r %%a in (*.?*) do (
MOVE "%%a" "D:\Destination folder\%%~nxa"
)
popd