Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

command line - How to copy files from folder tree dropping all the folders with Robocopy?

I have the following folder structure:

FolderA
--Folder1
--Folder2
--Folder3
...
--Folder99

Folders 1 through 99 have files in them.

All I want to do is to copy ALL THE FILES into ONE FOLDER, basically do a FolderA copy, and wipe out Folders 1-99 keeping all the files.

I'd like to do it with Robocopy from cmd.exe if possible (Windows Server 2008)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Why use robocopy? It's a good tool for a specific task but this is not the one.

You can simply use what cmd already gives you:

for /r %f in (*) do @copy "%f" target

This will essentially "flatten" your directory hierarchy. for /r will walk a directory tree recursively, looking for file names matching the given pattern. You can also specify the directory to start in:

for /r FolderA %f in (*) do @copy "%f" target

Within the loop it's just a simply copy of the file into a specified folder.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...