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

心已入冬 提交于 2019-12-17 18:15:04

问题


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)


回答1:


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.




回答2:


Robocopy is a great tool... when you have a job it can handle. Why not use xcopy?

If you have two drives you can just use xcopy:

XCOPY  C:\*.*  D:\NewFolder\   /S

Or use XXCOPY for one drive:

XXCOPY C:\*.*  C:\NewFolder\   /S /CCY

XXCOPY




回答3:


Get-ChildItem -Path source -Recurse -File | Move-Item -Destination dest


来源:https://stackoverflow.com/questions/1502170/how-to-copy-files-from-folder-tree-dropping-all-the-folders-with-robocopy

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