Print

Robocopy contents of root directory into subdirectory

Posted in Software

I recently came across an environment where after migrating all the data from an old file server, with the introduction of a new SOE (Standard Operating Environment) the pathways to the users home drives was slightly different. I rectified this with the use of one of my all time favorite tools robocopy.

 

Old Home Drive Pathway: “D:\USERS\USERNAME”

 

New Home Drive Pathway: D:\USERS\USERNAME\MY DOCUMENTS”

 

Seems simple? Well it would have been if I copied everything to a my documents folder prior to the migration but after moving 500+ GB of data I needed another solution. It took a little bit of trial and error however I managed to get robocopy to create a sub folder of My Documents under each users home folder and then move the contents of the directory into the my documents folder. See the following syntax:

 

robocopy "D:\Users\Username" "D:\Users\Username\My Documents" /w:1 /r:1 /MOVE /e /xd "My Documents"

 

the switches on the command do the following:

 

 

/w:1              Wait for 1 second before retrying

/r:1                Retry once before skipping

/MOVE            Move files and directories and delete from source after copy

/e                  Copy sub directories including empty dirs

/xd                 Exclude My Documents directory

 

The XD switch is quite important, if you don’t include this then it could potentially cause a loop in the copy the data within my documents subfolders until the script is stopped, so be sure to test prior to executing.