Copy files without recreating subdirectories

时光总嘲笑我的痴心妄想 提交于 2020-01-14 04:27:48

问题


I have a directory that has about 100 subfolders and close to 2,000 files within those subfolders (up to 4 layers). The files are .txt or .log, and each extension has a unique file name. I need to move or copy (whichever is faster) the files to the root of a different folder without recreating the subfolder structure like xcopy does. This is on Windows xp

Thanks in advance.

Existing:

Dir1\Folder1\000111.txt
Dir1\Folder2\000112.txt
Dir1\Folder3\000113.log
Dir1\Folder4\Dir2\000114.txt
Dir1\Folder4\Dir2\000115.txt
Dir1\Folder4\Dir2\000116.log
Dir1\Folder5\Dir3\000117.log
Dir1\Folder5\Dir3\000118.txt
Dir1\Folder5\Dir3\Dir4\000119.txt
Dir1\Folder5\Dir3\Dir4\000120.txt
Dir1\Folder5\Dir3\Dir4\000120.log
Required:
Dir9\000111.txt
Dir9\000112.txt
Dir9\000113.log
Dir9\000114.txt
Dir9\000115.txt
Dir9\000116.log
Dir9\000117.log
Dir9\000118.txt
Dir9\000119.txt
Dir9\000120.txt
Dir9\000120.log

回答1:


How about something like:

for /R %f in (*.txt,*.log) do copy %f dir9\%~nf

Issue this with dir1 as your working directory.

Have a read of for /? to understand why this works.

When I work on for statements I tend to try them out first like so:

for /R %f in (*.txt,*.log) do @echo copy %f dir9\%~nf


来源:https://stackoverflow.com/questions/4845046/copy-files-without-recreating-subdirectories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!