Results 1 to 14 of 14
  1. #1
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Robocopy need help with syntex

    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:\Users\Dave\Documents\Temp Files\ or "My Music" etc. the same goes when trying to select a source or destination folder.
    any help would be appreciated

  2. #2
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,853
    Thanks
    19
    Thanked 110 Times in 104 Posts
    Yes, 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%
    Last edited by BATcher; 2011-03-25 at 16:44.
    BATcher

    Dear Diary, today the Hundred Years War started ...

  3. #3
    Platinum Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,833
    Thanks
    7
    Thanked 252 Times in 237 Posts
    I 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=\\<servername>\c$\<folder>\
    
    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

  4. #4
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Batcher;
    How about a sample of the "higher batch file" that set the variables %Source% & %target% hopefully with folders that have the offending spaces in the name?
    Thanks

  5. #5
    Platinum Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,833
    Thanks
    7
    Thanked 252 Times in 237 Posts
    set _src=C:\Documents and Settings
    copy "%_src" d:\

    cheers, Paul

  6. #6
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Paul T View Post
    set _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 following

    robocopy G:\"Can Art"\ C:\"Users\Doc\Documents\Can Art"\ *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-CanArt.log

    But it would not work. So now you say try some thing like...

    set Source =G:\Can Art\
    Set Target =C:\Users\Doc\Documents\Can Art\
    robocopy "%Source%" "%Target%" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-CanArt.log
    Last edited by Doc666; 2011-04-03 at 19:59. Reason: clarification

  7. #7
    5 Star Lounger Browni's Avatar
    Join Date
    Dec 2009
    Location
    Rochdale, UK
    Posts
    904
    Thanks
    17
    Thanked 59 Times in 59 Posts
    Quote Originally Posted by Doc666 View Post
    so robobcopy does not need the quotes in the variable definition?
    So far I had been trying thing like the following

    robocopy G:\"Can Art"\ C:\"Users\Doc\Documents\Can Art"\ *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-CanArt.log

    But it would not work. So now you say try some thing like...

    set Source =G:\Can Art\
    Set Target =C:\Users\Doc\Documents\Can Art\
    robocopy "%Source%" "%Target%" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-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:\Users\Doc\Documents\Can Art\" /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-CanArt.log

  8. #8
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Thumbs down nothing works

    Quote Originally Posted by Browni View Post
    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:\Users\Doc\Documents\Can Art\" /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Users\Doc\Documents\Apps\Logs\XHAF-CanArt.log
    I have tried all of the following combinations
    Set 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:\Temp\CanArt.log
    pause


    Set zx ="C:\Can Art\"
    Set zz="C:\Temp\Can Art\"
    set
    pause
    robocopy "%zx%" "%zz%" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Temp\CanArt.log
    pause

    Set 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:\Temp\CanArt.log
    pause

    Set 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:\Temp\CanArt.log
    pause


    set
    pause
    robocopy "C:\Can Art\" "C:\Temp\Can Art\" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Temp\CanArt.log
    pause

    robocopy C:\"Can Art"\ C:\Temp\"Can Art"\ *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Temp\CanArt.log
    pause

    but none work robocopy just does not like spaces in the folder names

  9. #9
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,853
    Thanks
    19
    Thanked 110 Times in 104 Posts
    All 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 Settings\Fish Fingers
    robocopy "%source%" ...

    or
    set source="C:\Documents and Settings\Fish 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 drive\Monday
    
    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:\logs\CtoE.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

    Dear Diary, today the Hundred Years War started ...

  10. #10
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BATcher View Post
    All 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 Settings\Fish Fingers
    robocopy "%source%" ...

    or
    set source="C:\Documents and Settings\Fish 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 drive\Monday
    
    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:\logs\CtoE.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:\Temp\Can Art\
    robocopy %Source% "%Dest%" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Temp\CanArt.log
    pause


    And here's what I get back...

    C:\Documents and Settings\Tomd\My Documents>Set Source ="C:\Can Art\"
    C:\Documents and Settings\Tomd\My Documents>Set Dest =C:\Temp\Can Art\
    C:\Documents and Settings\Tomd\My Documents>robocopy "" *.* /s /XO /PURGE /R:1
    /W:1 /NP /TEE /Log:C:\Temp\CanArt.log

    2011/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 \\server\share\path).
    destination :: Destination Dir (drive:\path or \\server\share\path).
    /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 Settings\Tomd\My Documents>pause
    Press any key to continue . . .
    Last edited by Doc666; 2011-04-04 at 19:54.

  11. #11
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,853
    Thanks
    19
    Thanked 110 Times in 104 Posts
    Try removing the trailing \ from the path...
    BATcher

    Dear Diary, today the Hundred Years War started ...

  12. #12
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BATcher View Post
    Try removing the trailing \ from the path...
    Nope results are the same as before

    C:\Documents and Settings\Tomd\My Documents>Set Source ="C:\Can Art"
    C:\Documents and Settings\Tomd\My Documents>Set Dest =C:\Temp\Can Art
    C:\Documents and Settings\Tomd\My Documents>robocopy "" *.* /s /XO /PURGE /R:1
    /W:1 /NP /TEE /Log:C:\Temp\CanArt.log

    2011/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 \\server\share\path).
    destination :: Destination Dir (drive:\path or \\server\share\path).
    /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 !

  13. #13
    Platinum Lounger
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    3,833
    Thanks
    7
    Thanked 252 Times in 237 Posts
    I 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

  14. The Following User Says Thank You to Paul T For This Useful Post:

    Doc666 (2011-04-05)

  15. #14
    Star Lounger Doc666's Avatar
    Join Date
    Jan 2002
    Location
    Caledon, Ontario, Canada
    Posts
    89
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Paul; thanks much finally a version of the code that worked see below

    Set Source=C:\Can Art
    Set Dest=C:\Temp\Can Art
    robocopy "%Source%" "%Dest%" *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:\Temp\CanArt.log
    pause
    Quit

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •