问题
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.logRequired:
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