• 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.
    Author
    Topic
    #475679

    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:

    Viewing 5 reply threads
    Author
    Replies
    • #1273480

      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%

      BATcher

      Plethora means a lot to me.

      • #1274360

        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

    • #1273522

      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=\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
    • #1274363

      set _src=C:Documents and Settings
      copy “%_src” d:

      cheers, Paul

      • #1274365

        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:”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
        🙂

        • #1274461

          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:”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

          • #1274509

            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

            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
            pause

            Set 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
            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:TempCanArt.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:TempCanArt.log
            pause

            set
            pause
            robocopy “C:Can Art” “C:TempCan Art” *.* /s /XO /PURGE /R:1 /W:1 /NP /TEE /Log:C:TempCanArt.log
            pause

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

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

            • #1274512

              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 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.

            • #1274571

              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 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
              pause

              And 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.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 \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 . . .

    • #1274583

      Try removing the trailing from the path…

      BATcher

      Plethora means a lot to me.

      • #1274605

        Try 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.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 \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 !

    • #1274624

      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

    • #1274636

      Paul; thanks much finally a version of the code that worked see below

      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
      pause
      Quit

    Viewing 5 reply threads
    Reply To: Robocopy need help with syntex

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: