Robocopy.exe fails with root directories and double quotes

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Robocopy.exe fails with root directories and double quotes

#1 Post by foxidrive » 14 Apr 2015 01:15

if you double quote a root directory as a source or target path then robocopy will behave like it's drunk.

Code: Select all

@echo off
cd /d c:\
robocopy "c:\" "d:\" "*.bat"
pause



-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------

Started : Tuesday, 14 April 2015 17:15:08
Source : c:\" d:"\
Dest -

Files : *.bat

Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : No Destination Directory Specified.



This works:


Code: Select all

@echo off
cd /d c:\
robocopy c:\ d:\ "*.bat"
pause


-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------

Started : Tuesday, 14 April 2015 17:17:37
Source : c:\
Dest : d:\

Files : *.bat

Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

1 c:\
100% New File 24 autoexec.bat

------------------------------------------------------------------------------

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Robocopy.exe fails with root directories and double quot

#2 Post by penpen » 14 Apr 2015 03:00

It seems robocopy uses some kind of character escaping (at least on win8.1), just try:

Code: Select all

robocopy "c:\\" "Z:\\" "*.bat"

Avoiding backslash characters seems to work:

Code: Select all

robocopy "c:/"  "Z:/" "*.bat"
robocopy c:/  Z:/ *.bat


penpen

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Robocopy.exe fails with root directories and double quot

#3 Post by npocmaka_ » 14 Apr 2015 03:56

If either the source or desination are a "quoted long foldername" do not include a trailing backslash as this will be treated as an escape character, i.e. "C:\some path\" will fail but "C:\some path\\" or "C:\some path\." or "C:\some path" will work.


here's an excerpt from ss64 help page.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Robocopy.exe fails with root directories and double quot

#4 Post by Squashman » 14 Apr 2015 06:19

That makes sense. I am assuming if you just used the drive letter with a colon it would work as well.

mcnd
Posts: 27
Joined: 08 Jan 2014 07:29

Re: Robocopy.exe fails with root directories and double quot

#5 Post by mcnd » 14 Apr 2015 09:42

This is the standard behaviour from the c runtime argument handling routines and logic used in most of the command line tools. (https://msdn.microsoft.com/en-us/library/a1y7w461.aspx)

If you need to indicate the root folder, just use

Code: Select all

robocopy "c:\." "d:\."

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Robocopy.exe fails with root directories and double quot

#6 Post by foxidrive » 15 Apr 2015 08:08

penpen wrote:It seems robocopy uses some kind of character escaping (at least on win8.1)
Avoiding backslash characters seems to work:

penpen


They are interesting workarounds penpen.

Squashman wrote:I am assuming if you just used the drive letter with a colon it would work as well.


That would depend on the current working directories - and it does work without any double quotes at all too.

Post Reply