ROBOCOPY - Copy folders content to a single folder.

December 31, 2011 at 11:53:27
Specs: Windows 7
Here is some code I made :)

@echo off
set source="R:\Contracts\"
set destination="R:\Contracts\Sites\"
ROBOCOPY %source% %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0 /S
for /r %source in (*) do @copy "%destination" .


R:\Contracts\ is full of folders which have files in them.

I want to copy all to R:\Contracts\Sites\ and flatten the folder structure.

Everything copies well but also the folder structure.

Thank you


See More: ROBOCOPY - Copy folders content to a single folder.

Report •

#1
January 1, 2012 at 18:02:28
This works......

@echo on
set source="C:\folders"
set destination="C:\folder2"


for /r %source% %%F in (.) do if "%%~fF" neq %destination% ROBOCOPY %%F %destination% *.srt *.pdf *.mp4 *.jpg *.txt /COPYALL /R:0


Report •

#2
January 3, 2012 at 03:37:24
Hello, I have a question please.
When I set the source and destination with a short file name it all works however if I user a long files name e.g.

"c:\files\contract open\site\usa\ content clean\over load\psjj200"

it does not seem to work.

Any help please


Report •

#3
January 3, 2012 at 05:54:27
Hello,

I could really use some help. I am not sure why a LONG file name location would cause this error. Can anyone shed some light on this please.

Thank you


Report •

Related Solutions

#4
January 3, 2012 at 13:22:48
Here is the solution.

::Not sure if this is needed
::It guarantees you have a canonical path (standard form)
for %%F in (%destination%) do set destination="%%~fF"

for /r %source% %%F in (.) do if "%%~fF" neq %destination% ROBOCOPY "%%F" %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0

Thanks to dbenham


Report •

Ask Question