Robocopy directories and filenames with spaces
Caution – this post is for computer geeks. All other posts are approved for general consumption.
Using robocopy makes many tasks easier with its robust switches and command line options. One thing that is not easily determined and is not readily defined in the help or online is how to use robocopy with file names and folders that contain spaces. After some quick trial and error I determined one way to make it work without using scripting code.
I came across this issue recently when migrating a small business server, sbs2003, to sbs2011, which as an aside is much easier than migrating to sbs2008. For example, if you have a share on a server named server01 and want to copy it to the local server from which you are working and the server share has space in the filename such as “Health Benefits,” normally you would open a command prompt using runas administrator and then enter:
robocopy \\server01\Health Benefits\ C:\Data\HealthBenefits\ /E /R:10 /COPY:DATSOU /LOG:C:\Copy_HB_results.txt
However, this does not provide the correct input syntax for robocopy and the copy does not run. It sees the destination incorrectly as the word immediately following the space, in this case Benefits.
I hope this helps others as it will make it much easier, imho, than scripting for those not familiar with specific scripting syntax. I know I’ll be using it more for sbs 2011 migrations and other server maintenance.