Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 562
roman m Avatar asked Oct 01 '09 06:10

roman m


People also ask

Why is Robocopy skipping all files?

SKIPPED via robocopy means that source and target versions of the file are same.. SO, it just skips the copy. You can use /is option to overwrite even the exactly same files. Welcome to Super User!

Does Robocopy copy subfolders by default?

Robocopy does not copy subdirectories by default. copy subdirectories, including Empty ones. Same as /S, but it also copies empty subdirectories. Will automatically add /S into the command.

Does Robocopy copy folders?

The Basics: Copying Files The most basic use of robocopy is using a source and destination directory with no options. This option will copy all files (excluding subfolders) from C:\src to C:\dst. You can also copy everything including subfolders (empty or not) and NTFS permissions.


2 Answers

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.

like image 85
Joey Avatar answered Oct 07 '22 09:10

Joey


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

like image 21
NitroxDM Avatar answered Oct 07 '22 08:10

NitroxDM