I need to find a way to enter or exclude directory names with a Space in them in the Robocopy command string /XD excludes directories but pukes when you list a directory with a space such as C:UsersDaveDocumentsTemp Files or “My Music” etc. the same goes when trying to select a source or destination folder. :confused:
any help would be appreciated :rolleyes:
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Robocopy need help with syntex
Home » Forums » AskWoody support » Windows » Windows – other » Robocopy need help with syntex
- This topic has 13 replies, 4 voices, and was last updated 14 years ago.
AuthorTopicWSDoc666
AskWoody LoungerMarch 25, 2011 at 1:56 pm #475679Viewing 5 reply threadsAuthorReplies-
BATcher
AskWoody_MVPMarch 25, 2011 at 3:41 pm #1273480Yes, you always need to put “directory paths with one or more spaces in them in double quotes” when using the command line.
Example (%source%, %target% and %log% were set higher up in the BATch file):Code:set opts=/copyall /mir /np /r:0 /w:0 /ndl /xj set opts=%opts% /xd Backup "System Volume Information" RECYCLER "Recycle Bin" robocopy %source% "%target%" %opts% >> %log%
BATcher
Plethora means a lot to me. -
WSDoc666
AskWoody Lounger
-
Paul T
AskWoody MVPMarch 26, 2011 at 1:46 am #1273522I always set the retry and wait values to 0, as shown by BATcher. Waiting 30 seconds between 1 million retries is just silly.
No file or directory list (NFL and NDL) is also really useful as you don’t want a huge list cluttering up the log file, only the errors.
Turn off the progress indicator if using in a batch file (NP).
I also use the log+ option to append all output to my file of choice, rather than the DOS redirect (>).cheers, Paul
Code:@echo off rem ***************************************************************************** rem Script Robocopies the File Server files to a new Location rem rem author : Lee rem rem Edit History : Paul, added /NDL /NFL /NP to turn off file logging rem and progress indicator. rem Choose the required form of copy. rem Use create first, then schedule Update. rem Copy Security last. rem Paul, added time and date to log file name. rem Paul 7/2005, Added step numbers. Modified Copy security command. rem . rem ***************************************************************************** REM CHANGE THIS to a new folder ; make sure there is enough space on the destination server. setlocal set Orig_Server=F: set Dest_server=\c$ for /f “tokens=1,2 delims=: ” %%x in (“%time%”) do set EFtime=%%x%%y for /f “tokens=2-4 delims=/ ” %%x in (“%date%”) do set EFdate=%%z%%y%%x set errorfile=DataError%EFdate%%EFtime%.txt Rem Edit the file for whichever command you want to use. Rem Use steps in order for efficient copying. Rem STEP 1 – RUN MANUALLY Rem Create file/directory structure only, do NOT copy security. Rem Prevents directory fragmentation and improves file system performance. Rem Verbose output. robocopy %Orig_Server% %Dest_server% /NDL /NFL /NP /S /E /COPY:DAT /CREATE /V /R:1 /W:1 /log+:%errorfile% Rem STEP 2 – SCHEDULE TO RUN NIGHTLY Rem Update, only copy files that are newer than the destination. Rem Delete files not in source. Rem Do NOT copy security. Rem Quiet, log summary and errors only. ::robocopy %Orig_Server% %Dest_server% /NDL /NFL /NP /MIR /COPY:DAT /R:1 /W:1 /log+:%errorfile% Rem STEP 3 – RUN MANUALLY AFTER THE LAST RUN OF STEP 2 Rem Copy Security, ownership and auditing data only. Rem Quiet, log summary and errors only. ::robocopy %Orig_Server% %Dest_server% /NDL /NFL /NP /S /E /IS /COPY:SOU /R:1 /W:1 /log+:%errorfile% Rem ALTERNATE COMMAND – PERFORM ALL 3 STEPS AT ONCE Rem Copy all data including security, delete files not in source. Rem Verbose output. rem robocopy %Orig_Server% %Dest_server% /MIR /COPYALL /ETA /V /R:1 /W:1 /log:%errorfile% Rem errorlevel checking if errorlevel 16 echo ERROR: ***FATAL ERROR*** >>%errorfile% & goto end if errorlevel 15 echo ERROR: FAIL MISM XTRA COPY >>%errorfile% & goto end if errorlevel 14 echo ERROR: FAIL MISM XTRA >>%errorfile% & goto end if errorlevel 13 echo ERROR: FAIL MISM COPY >>%errorfile% & goto end if errorlevel 12 echo ERROR: FAIL MISM >>%errorfile% & goto end if errorlevel 11 echo ERROR: FAIL XTRA COPY >>%errorfile% & goto end if errorlevel 10 echo ERROR: FAIL XTRA >>%errorfile% & goto end if errorlevel 9 echo ERROR: FAIL COPY >>%errorfile% & goto end if errorlevel 8 echo ERROR: FAIL >>%errorfile% & goto end if errorlevel 7 echo ERROR: MISM XTRA COPY >>%errorfile% & goto end if errorlevel 6 echo ERROR: MISM XTRA >>%errorfile% & goto end if errorlevel 5 echo ERROR: MISM COPY >>%errorfile% & goto end if errorlevel 4 echo ERROR: MISM >>%errorfile% & goto end if errorlevel 3 echo ERROR: XTRA COPY >>%errorfile% & goto end if errorlevel 2 echo ERROR: XTRA >>%errorfile% & goto end if errorlevel 1 echo * SUCCESSFUL COPY * >>%errorfile% & goto end if errorlevel 0 echo Notice: –no change, no data copied– >>%errorfile% & goto end :end
Paul T
AskWoody MVP-
WSDoc666
AskWoody LoungerApril 3, 2011 at 9:20 am #1274365set _src=C:Documents and Settings
copy “%_src” d:cheers, Paul
so robobcopy does not need the quotes in the variable definition?
So far I had been trying thing like the followingrobocopy G:”Can Art” C:”UsersDocDocumentsCan Art” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
But it would not work. So now you say try some thing like…
set Source =G:Can Art
Set Target =C:UsersDocDocumentsCan Art
robocopy “%Source%” “%Target%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
🙂 -
browni
AskWoody MVPApril 3, 2011 at 11:43 pm #1274461so robobcopy does not need the quotes in the variable definition?
So far I had been trying thing like the followingrobocopy G:”Can Art” C:”UsersDocDocumentsCan Art” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
But it would not work. So now you say try some thing like…
set Source =G:Can Art
Set Target =C:UsersDocDocumentsCan Art
robocopy “%Source%” “%Target%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
🙂I would guess that you have the quotes in the wrong place and also the wildcard is not required
Try
robocopy “G:Can Art” “C:UsersDocDocumentsCan Art” /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
-
WSDoc666
AskWoody LoungerApril 4, 2011 at 10:11 am #1274509I would guess that you have the quotes in the wrong place and also the wildcard is not required
Try
robocopy “G:Can Art” “C:UsersDocDocumentsCan Art” /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:UsersDocDocumentsAppsLogsXHAF-CanArt.log
I have tried all of the following combinations
Set Source =C:Can Art
Set Dest =C:TempCan Art
set
pause
robocopy “%Source%” “%Dest%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauseSet zx =”C:Can Art”
Set zz=”C:TempCan Art”
set
pause
robocopy “%zx%” “%zz%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauseSet Source=C:”Can Art”
Set Dest=”C:Temp”Can Art”
set
pause
robocopy “%Source%” “%Dest%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauseSet Source=C:”Can Art”
Set Dest=”C:Temp”Can Art”
set
pause
robocopy %Source% %Dest% *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauseset
pause
robocopy “C:Can Art” “C:TempCan Art” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauserobocopy C:”Can Art” C:Temp”Can Art” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pausebut none work robocopy just does not like spaces in the folder names:huh:
-
BATcher
AskWoody_MVPApril 4, 2011 at 10:38 am #1274512All you need to do is to write out the full path, without any double quotes, and containing spaces.
Then put double quotes as the first and last character.You could do this in two ways
set source=C:Documents and SettingsFish Fingers
robocopy “%source%” …or
set source=”C:Documents and SettingsFish Fingers”
robocopy %source% …It gives the same result.
What you cannot have is embedded double-quotes!
Here’s an almost actual example:
Code::setup the source and target paths for robocopy set source=C: set target=E:RoboCopy of %computername% C driveMonday set opts=/copyall /mir /np /r:0 /w:0 /ndl /xj set opts=%opts% /xd Recycler "System Volume Information" cache bases set opts=%opts% "Local Data" "Kaspersky Lab" winsxs "Recycle Bin" set opts=%opts% /xf hiberfil.sys pagefile.sys set log=E:logsCtoE.log robocopy %source% "%target%" %opts% > %log%
Note that neither the %source% environment variable nor the %log% one needs double quotes because neither contains one or more blanks…
BATcher
Plethora means a lot to me. -
WSDoc666
AskWoody LoungerApril 4, 2011 at 6:52 pm #1274571All you need to do is to write out the full path, without any double quotes, and containing spaces.
Then put double quotes as the first and last character.You could do this in two ways
set source=C:Documents and SettingsFish Fingers
robocopy “%source%” …or
set source=”C:Documents and SettingsFish Fingers”
robocopy %source% …It gives the same result.
What you cannot have is embedded double-quotes!
Here’s an almost actual example:Code::setup the source and target paths for robocopy set source=C: set target=E:RoboCopy of %computername% C driveMonday set opts=/copyall /mir /np /r:0 /w:0 /ndl /xj set opts=%opts% /xd Recycler "System Volume Information" cache bases set opts=%opts% "Local Data" "Kaspersky Lab" winsxs "Recycle Bin" set opts=%opts% /xf hiberfil.sys pagefile.sys set log=E:logsCtoE.log robocopy %source% "%target%" %opts% > %log%
Note that neither the %source% environment variable nor the %log% one needs double quotes because neither contains one or more blanks…
Here’s what I tried
Set Source =”C:Can Art”
Set Dest =C:TempCan Art
robocopy %Source% “%Dest%” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
pauseAnd here’s what I get back…
C:Documents and SettingsTomdMy Documents>Set Source =”C:Can Art”
C:Documents and SettingsTomdMy Documents>Set Dest =C:TempCan Art
C:Documents and SettingsTomdMy Documents>robocopy “” *.* /s /XO /PURGE /R:1
/W:1 /NP /TEE /Log:C:TempCanArt.log2011/04/04 19:43:01 ERROR 0 (0x00000000) Expanding Source Pathname
The operation completed successfully.——————————————————————————-
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
——————————————————————————-Started : Mon Apr 04 19:43:01 2011
Source –
Dest –Files :
Options : /COPY:dat /R:1000000 /W:30——————————————————————————
ERROR : Invalid Parameter #1 : “”
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:path or \serversharepath).
destination :: Destination Dir (drive:path or \serversharepath).
/MIR :: Mirror a complete directory tree.For more usage information run ROBOCOPY /? or read Robocopy.Doc.
NOTE: Read “True Replication” in Robocopy.Doc prior to first use of /MIR !
**** /MIR can DELETE files as well as copy them !C:Documents and SettingsTomdMy Documents>pause
Press any key to continue . . .
-
-
-
BATcher
AskWoody_MVP-
WSDoc666
AskWoody LoungerApril 5, 2011 at 9:43 am #1274605Try removing the trailing from the path…
Nope results are the same as before
C:Documents and SettingsTomdMy Documents>Set Source =”C:Can Art”
C:Documents and SettingsTomdMy Documents>Set Dest =C:TempCan Art
C:Documents and SettingsTomdMy Documents>robocopy “” *.* /s /XO /PURGE /R:1
/W:1 /NP /TEE /Log:C:TempCanArt.log2011/04/05 10:37:09 ERROR 0 (0x00000000) Expanding Source Pathname
The operation completed successfully.——————————————————————————-
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
——————————————————————————-Started : Tue Apr 05 10:37:09 2011
Source –
Dest –Files :
Options : /COPY:dat /R:1000000 /W:30——————————————————————————
ERROR : Invalid Parameter #1 : “”
Simple Usage :: ROBOCOPY source destination /MIR
source :: Source Directory (drive:path or \serversharepath).
destination :: Destination Dir (drive:path or \serversharepath).
/MIR :: Mirror a complete directory tree.For more usage information run ROBOCOPY /? or read Robocopy.Doc.
NOTE: Read “True Replication” in Robocopy.Doc prior to first use of /MIR !
**** /MIR can DELETE files as well as copy them !
Paul T
AskWoody MVPApril 5, 2011 at 12:23 pm #1274624I see a trailing space in the set commands before the equal sign. DOS/Windows will not thank you for that.
You should also add the “/quit” option when testing.
If you are going to use quotes anywhere, use them in the robocopy command and leave them out of the set command. Then you just add the the full path, spaces and all.
cheers, Paul
WSDoc666
AskWoody LoungerViewing 5 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Tracking content block list GONE in Firefox 138
by
Bob99
4 hours, 43 minutes ago -
How do I migrate Password Managers
by
Rush2112
4 hours, 5 minutes ago -
Orb : how fast is my Internet connection
by
Alex5723
9 hours, 4 minutes ago -
Solid color background slows Windows 7 login
by
Alex5723
10 hours, 25 minutes ago -
Windows 11, version 24H2 might not download via Windows Server Updates Services
by
Alex5723
8 hours, 55 minutes ago -
Security fixes for Firefox
by
Susan Bradley
8 hours, 24 minutes ago -
Notice on termination of services of LG Mobile Phone Software Updates
by
Alex5723
21 hours, 9 minutes ago -
Update your Apple Devices Wormable Zero-Click Remote Code Execution in AirPlay..
by
Alex5723
1 day, 6 hours ago -
Amazon denies it had plans to be clear about consumer tariff costs
by
Alex5723
21 hours, 13 minutes ago -
Return of the brain dead FF sidebar
by
EricB
8 hours, 24 minutes ago -
Windows Settings Managed by your Organization
by
WSDavidO61
7 hours, 33 minutes ago -
Securing Laptop for Trustee Administrattor
by
PeachesP
8 hours, 34 minutes ago -
The local account tax
by
Susan Bradley
9 hours, 45 minutes ago -
Recall is back with KB5055627(OS Build 26100.3915) Preview
by
Alex5723
1 day, 19 hours ago -
Digital TV Antenna Recommendation
by
Win7and10
1 day, 11 hours ago -
Server 2019 Domain Controllers broken by updates
by
MP Support
2 days, 7 hours ago -
Google won’t remove 3rd party cookies in Chrome as promised
by
Alex5723
2 days, 8 hours ago -
Microsoft Manager Says macOS Is Better Than Windows 11
by
Alex5723
2 days, 11 hours ago -
Outlook (NEW) Getting really Pushy
by
RetiredGeek
1 day, 14 hours ago -
Steps to take before updating to 24H2
by
Susan Bradley
1 day, 5 hours ago -
Which Web browser is the most secure for 2025?
by
B. Livingston
1 day, 18 hours ago -
Replacing Skype
by
Peter Deegan
1 day, 7 hours ago -
FileOptimizer — Over 90 tools working together to squish your files
by
Deanna McElveen
2 days, 5 hours ago -
Excel Macro — ask for filename to be saved
by
nhsj
1 day, 3 hours ago -
Trying to backup Win 10 computer to iCloud
by
SheltieMom
1 day, 7 hours ago -
Windows 11 Insider Preview build 26200.5570 released to DEV
by
joep517
4 days, 11 hours ago -
Windows 11 Insider Preview build 26120.3941 (24H2) released to BETA
by
joep517
4 days, 13 hours ago -
Windows 11 Insider Preview Build 22635.5305 (23H2) released to BETA
by
joep517
4 days, 13 hours ago -
No April cumulative update for Win 11 23H2?
by
Peobody
3 days, 1 hour ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
4 days, 14 hours ago
Recent blog posts
Key Links
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.