Link to home
Start Free TrialLog in
Avatar of Dan_Scott
Dan_Scott

asked on

RoboCopy command with a space in the UNC

I am going to use RoboCopy in a batch to copy a directory to 80 NT4 servers overnight. I am having problems running it because of the UNC:
C:\>Robocopy "\\server1\home\grimer\business plan 2005" "\\%1\d$\Group\"Business Plan\"" /MIR /R:4

When I tried to run robocopy straight from cmd I had the following error:

   Source : \\server1\home\grimer\business plan 2005\
     Dest : \\server2\d$\Group\Business Plan" \MIR \R\
    Files : *.*
  Options : *.* /R:1000000 /W:30
ERROR 123 (0x0000007B) Accessing Destination Directory \\server2\d$\Group\Business Plan" \MIR \R\
The filename, directory name, or volume label syntax is incorrect.

Looks like a problem with the space in the destination UNC. It has read the quotation and switches as part of the destination. Any idea how I can replace this in the syntax? Changing the folder name on the servers is not an option.
Avatar of Pete Long
Pete Long
Flag of United Kingdom of Great Britain and Northern Ireland image

are you sure its the space?

I may incorrect but I dont think

\\server\adiminstativeshare$\folder

is a legal path?

Try moving the first (opening) quote inside the \\

Advise.
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sciwriter
sciwriter

In any windows long file name path, especially with spaces, always use the "quotes" --

C:\This directory\My folder\ here is the file   -- that will give windows fatal siezures.

But -- "C:\This directory\My folder\ here is the file"   -- that is copacetic, windows loves it, because of the quotes.
there are missing quotes in your batchfile: place them always before and after the complete UNC-path.
I recently hired on to a new job and was writing a script to help with some file replication using trusty old Robocopy but everytime I tried to copy from the local PC I too got this error "ERROR 123 (0x0000007B) Accessing Source Directory c:\temp\docs.txt\The filename, directory name, or volume label syntax is incorrect."

Now I know the path is correct. I know it is. I have xcopied the same file... in fact I just deleted the "robo" & added "x" into the script ad ran it again without any issues. I've ran it as admin, so it's not a permissions issue. I can use it when the source is something other than the local hard drive and it works as always. The only time I get a problem is copying from the C:\, and that doesn't jive.

I've ran this on NT 4.0 (SP6a) & Win2K boxes and got the same error. I've tried both 1.95 & 1.96 & again same error. I've changed directories c:\tbd or C;\temp, used quotes for both source or target directories, ran as admin.....as myself.....I'm puzzled.

The command resembles this c:\temp\docs.txt c:\tbd /mir /np , so you see there's nothing fancy happening here. I gotta be overlooking something but I couldn't tell you what it is.....

The same command will work if I change the drive letters to a network share, so what's the deal? Can you help?

Maybe I'm overlooking something, if so I apologize but I'm stumped. Thanks again.

-Chad
Avatar of Dan_Scott

ASKER

When I was getting the syntax is incorrect error, it turned out to be as simple as having an extra \ at the end of the destination UNC. Robocopy did not read this as the end of the path so read the destination as \\server2\d$\Group\Business Plan" \MIR \R\  - including the switches!
This might be irrelevent, but in your error you have also got this errant backslash:
"c:\temp\docs.txt\"
If this is no help then put in the full error in and I'll try to replicate it.

Scotty.
I noticed that "\" as well but I didn't type it, rather that's what robocopy is returning. I assumed it was just a function of the app.

All I am doing at this point is trying to copy a test file from 1 temp dir to another temp dir off the local PC. So this is what I type;

robocopy c:\test\file.doc c:\tbd

No switches, just to elimainate possible errors. I can run xcopy with the same locales with no issues. I've ran robocopy hundreds of times....literally, and never seen this. I am assuming I'm overlooking something silly & I'll feel stupid when someone points it out but at this point it's worth it.  

Also I can change drive letters & it'll run smoth. So if I copy from the netowrk to my PC, no problems. PC to network....whoa there, that's crazy talk. Very bizarre.

Thanks for the help.

-Chad
OK, I think I see a pattern but I'm not sure how to fix it.

I've noticed that when I specify a file in the robocopy command the "\" is included at the end of the path in the description & log, which would appear to doing what you suggested.....appending the path. The thing is I'm not including it in the command or the script. This is why it's not working.....but if I just specify a folder then it'll run fine. So the problem is specifying single files to be copied. How can I get robocopy to copy over a single file without generating an error?

I only need 4 small files from a decent sized folder, it'd be a shame if I had to bring it all over & do a del *.extension.....missing something here. Why is it doing this? Thanks.

-Chad
I've just lookied at all of my old robocopy scripts & I can't find a single one that copies over a specific file. It's always a whole directory (ies). I never noticed that. All this time. I do have one that I don't remember writing  from 1999 that us /XD & /XF for a directory......perhaps this is why?

I knew I'd feel silly.
That's by design; have a look at robocopy.doc or the extended help of robocopy:
Usage : ROBOCOPY source destination [file [file]...] [options]
source : Source Directory (drive:\path or \\server\share\path).
destination : Destination Dir  (drive:\path or \\server\share\path).
file : File(s) to copy  (names/wildcards: default is "*.*").

Source and Destination are *directories*; files (or exclusions) have to be listed separately.
Well I read through that doc half a dozen times in an effort to double check my assumptions  & somehow missed that......but you're right. It's all in there. Man, that's embarrassing. Thanks for taking the time to straighten me out. Much appreciated.

-Chad
With robocopy you need to place the quotes correctly. Using your example: C:\This directory\My folder\ you need to use "C:\This directory\My folder"\ but place the second quotes prior to the backslash. This can be used for UNC paths as well and for source and destination directories.
bodhi1971:

Your robocopy command should read robocopy c:\temp\ c:\tbd docs.txt /mir /np

robocop[y source destination files to copy defaults to *.* options.