0
votes

I am trying to create a batch script to copy multiple directories in different locations into one single directory in another location. The problem is that robocopy is copying the internal contents of the root directory and not the root directory itself

So If I have 3 directories in location a being : C:\dir1 , C:\dir2 , C:\dir3

and I want to copy them to one single folder onto another location ex: D:\dirBackups

so that the outcome would be D:\dirBackups\dir1 , D:\dirBackups\dir2, D:\dirBackups/dir3

Currently robocopy is copying the stuff inside dir1 , dir2 and dir3 so I am ending up with the contents of the three directories all into D:\dirBackups

I am using the following code

for /F "tokens=*" %%A in (%pathsFile%) do (
   robocopy %%A D:\dirBackups /E /COPYALL /XF /SEC /SECFIX /TIMFIX /W:0 /R:1 /REG /XJ /Z /FFT
)

%pathsFile% is a text file which contains the directories to be backed up into D:\dirBackups, so I am looping through the file and for each line I am triggering the same robocopy Command.

The files are getting copied well but the root directory is never included so it's working like it's expanding all the folders and only copying the inner content of each folder into one location.

Thanks

1
It should be a back slash D:\dirBackups not a forward slash D:/dirBackups. Also you don't need to use /SEC, which is equivalent to /COPY:DATS, as you have already used /COPYALL, which is equivalent to /COPY:DATSOU. In addition your /XF option does not name any files to exclude, enter ROBOCOPY /? into a Command prompt window for more information on the command. - Compo
My Paths are infact using \ not / I did a mistake when typing this in... and thanks for the information, but any clue how I can copy multiple folders from the root into one folder on another end ? thanks - Eric

1 Answers

1
votes

How does this work for you?

@ECHO OFF
FOR /F "USEBACKQ DELIMS=" %%A IN ("%pathsFile%") DO (
    ROBOCOPY "%%~A" "D:\dirBackups\%%~nxA" /E /Z /COPYALL /SECFIX /TIMFIX /XJ /FFT /R:1 /W:0 /REG
)