Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Robocopy Command  (Read 9593 times)

0 Members and 1 Guest are viewing this topic.

Jiafu

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    Robocopy Command
    « on: September 01, 2016, 08:39:57 AM »
    Hi all,

    Recently, I have create robocopy batch file the following are the code use:

    @echo off

    rem Copy folders and subdirectories.
    robocopy "C:\Users\Owner\Desktop\New folder" "K:\New folder" /e /w:1 /r:5 /zb
    robocopy "C:\Users\Owner\Desktop\New folder (2)" "K:\New folder2" /e /w:1 /r:5 /zb

    rem Copy specified files in the folders and subdirectories folders.
    robocopy "C:\Users\test\Documents" "D:\Outlook" "Bowling Competition 2015 (Inter-Site).xlsx" /w:1 /r:5 /zb

    echo.

    :exit

    pause


    After running the batch file as administrator, I receive the following error: The filename, directory name, or volume label syntax is incorrect. But the file has been transfer successfully, and I am able to view the file. Anyone has any solutions or did I need to add in additional commands in order to rectify the error.

    Spoiler



      Specialist

      Thanked: 50
    • Experience: Beginner
    • OS: Windows XP
    Re: Robocopy Command
    « Reply #1 on: September 01, 2016, 10:05:29 AM »
    https://technet.microsoft.com/en-us/magazine/2009.04.utilityspotlight.aspx

    I always liked robocopy....why not use the GUI version?
    Whenever I watch TV and I see those poor starving kids all over the world, I can't help but cry. I mean I would love to be skinny like that, but not with all those flies and death and stuff." - Mariah Carey, Pop Singer

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Robocopy Command
    « Reply #2 on: September 01, 2016, 03:41:46 PM »
    It is covered in the CH archives.
    http://www.computerhope.com/robocopy.htm

    elkhateib



      Rookie

      Thanked: 1
      • Experience: Experienced
      • OS: Windows 7
      Re: Robocopy Command
      « Reply #3 on: September 02, 2016, 05:24:02 AM »
      Hi all,

      Recently, I have create robocopy batch file the following are the code use:

      @echo off

      rem Copy folders and subdirectories.
      robocopy "C:\Users\Owner\Desktop\New folder" "K:\New folder" /e /w:1 /r:5 /zb
      robocopy "C:\Users\Owner\Desktop\New folder (2)" "K:\New folder2" /e /w:1 /r:5 /zb

      rem Copy specified files in the folders and subdirectories folders.
      robocopy "C:\Users\test\Documents" "D:\Outlook" "Bowling Competition 2015 (Inter-Site).xlsx" /w:1 /r:5 /zb

      echo.

      :exit

      pause


      After running the batch file as administrator, I receive the following error: The filename, directory name, or volume label syntax is incorrect. But the file has been transfer successfully, and I am able to view the file. Anyone has any solutions or did I need to add in additional commands in order to rectify the error.



      @ECHO OFF
      SETLOCAL

      SET _source=c:\user\owner\desktop\new folder

      SET _dest=k:\new folder

      SET _what=/e /w /r /zb

      SET _options=/R:0 /W:0 /LOG:C:\batch\RoboLog.txt /NFL /NDL
      :: /R:n :: number of Retries
      :: /W:n :: Wait time between retries
      :: /LOG :: Output log file
      :: /NFL :: No file logging
      :: /NDL :: No dir logging

      ROBOCOPY %_source% %_dest% %_what% %_options%


      this is how should be look like

      for more info.
      http://ss64.com/nt/robocopy.html

      Jiafu

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows 7
        Re: Robocopy Command
        « Reply #4 on: September 02, 2016, 09:45:19 AM »
        @spoiler for robocopy GUI version which I find online it require installation, unless robocopy GUI version online have portable which does not require any installation.

        hmmmm............

        @elkhateib I will give it a try with the command, but if I want to transfer 2 or more files into the other folder/local drive or even transfer individual file in the folder to other folder/local drive, how will I be able to write the command to execute it?

        elkhateib



          Rookie

          Thanked: 1
          • Experience: Experienced
          • OS: Windows 7
          Re: Robocopy Command
          « Reply #5 on: September 02, 2016, 11:33:37 AM »
          @spoiler for robocopy GUI version which I find online it require installation, unless robocopy GUI version online have portable which does not require any installation.

          hmmmm............

          @elkhateib I will give it a try with the command, but if I want to transfer 2 or more files into the other folder/local drive or even transfer individual file in the folder to other folder/local drive, how will I be able to write the command to execute it?

          Example:
          Start /Min "Job one" Robocopy \\FileServA\C$\Database1 \\FileServeBackupA\c$\Backups
          Start /Min "Job two" Robocopy \\FileServB\C$\Database2 \\FileServeBackupB\c$\Backups

          elkhateib



            Rookie

            Thanked: 1
            • Experience: Experienced
            • OS: Windows 7
            Re: Robocopy Command
            « Reply #6 on: September 02, 2016, 11:58:41 AM »
            or u can do this
            (put it in text file and change the file extension from .txt to .cmd)
            definitely want to put in an appropriate source and destination directory to replace my temporary placeholders (“c:\temp” and “c:\testdir”)
            By default this script will loop through the subdirectories of SOURCE and kick off simultaneous robocopy threads for each processor/core on your machine. You can change the number of threads as indicated from default to any number desired "THREADS=4 for four simultaneous robocopy operations"
            This script is particularly useful for taking advantage of processor and spindle performance when synchronizing directories that contain hundreds or thousands of subdirectories


            @echo off
            cls
            color 2a
            title Multi-Threaded Robocopy
            SETLOCAL ENABLEDELAYEDEXPANSION

            :: Multi-Threaded Robocopy ::
            ::
            :: Kicks off a robocopy instance for every processor on your machine
            :: Monitors for termination of robocopy instances and spawns new ones to take their place
            ::
            :: Robocopy.exe must be somewhere in PATH - Already the case in newer versions of Windows
            ::
            :: Change variables below to suit your needs


            set SOURCE=%systemdrive%\temp
            set DEST=%systemdrive%\testdir
            set OPTS=/mir /np /w:3 /r:3
            set /a THREADS=%NUMBER_OF_PROCESSORS%


            echo.
            echo Copying %THREADS% folders at a time from "%SOURCE%" to "%DEST%"
            echo.
            echo With options "%OPTS%"
            echo.
            pause


            set FOLDER=0
            set FOLDERNUM=0
            set RUNCOUNT=0


            :: Kick off primary loop that iterates through directories under %SOURCE%:

            for /f "tokens=* delims=" %%a in ('dir /a:d /b "%SOURCE%"') do (
                                 set FOLDER=%%a
                                 :STARTLOOP
                                 if !RUNCOUNT! LSS %THREADS% (
                                          call :WORK
                                          ) else (
                                          call :KILLTIME                              
                                          )
                                 )


            :: Finished primary loop so folder copies are done:
            goto :DONE


            :: Spawn a robocopy thread and increment our count:
            :WORK
            set /a RUNCOUNT=!RUNCOUNT!+1
            set /a FOLDERNUM=!FOLDERNUM!+1
            echo.
            echo Folder number !FOLDERNUM! is: "%SOURCE%\%FOLDER%"
            start "Robocopy Folder Number:!FOLDERNUM!" robocopy.exe "%SOURCE%\%FOLDER%" "%DEST%\%FOLDER%" %OPTS%
            goto :EOF


            :: Robocopy threads are currently running so we wait and check again before spawning new:
            :KILLTIME
            call :GETRUNNING
            if %RUNCOUNT% LSS %THREADS% (
                     goto :WORK
                     ) else (
                     goto KILLTIME
                     )



            :::::::::::::
            :: Subroutine to get count of running instances of robocopy.exe:
            :GETRUNNING
            ping -n 6 localhost >nul
            set RUNCOUNT=0
            for /f "tokens=1 delims=," %%b in ('tasklist /fo csv /nh /fi "imagename eq robocopy.exe"^| findstr /v "INFO:"') do (
                                             set /a RUNCOUNT=!RUNCOUNT!+1
                                             )
            goto :EOF
            ::End of GETRUNNING subroutine
            :::::::::::::


            :DONE

            :: Robocopy remaining files that live in root of source directory:
            :COPYFILES
            echo.
            echo Copying remaining files from "%SOURCE%" to "%DEST%"...
            start "Robocopy Files in %SOURCE%" /wait robocopy.exe "%SOURCE%" "%DEST%" /purge /np /w:3 /r:3

            :ALLDONE

            :: Check for remaining instances of robocopy.exe and wait for completion before continuing:
            call :GETRUNNING
            if .%RUNCOUNT%. NEQ .0. (goto :ALLDONE)

            echo.
            echo Done
            echo.
            echo We stopped Copying at folder "%SOURCE%\%FOLDER%"
            echo.
            pause

            set SOURCE=
            set DEST=
            set OPTS=
            set THREADS=
            set RUNCOUNT=
            set FOLDER=
            set FOLDERNUM=


            ENDLOCAL

            goto :END


            :END

            Jiafu

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows 7
              Re: Robocopy Command
              « Reply #7 on: September 02, 2016, 08:00:05 PM »
              @ elkhateib, if there is an error: The filename, directory name, or volume label syntax is incorrect when robocopy batch file has been executed will it affect the files and folder I transfer, as it seem like the transfer files and folders size is the same

              Jiafu

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Windows 7
                Re: Robocopy Command
                « Reply #8 on: September 02, 2016, 08:08:35 PM »
                @elkhateib, is it possible don't use variables for robocopy batch file. Can I just use robocopy [source] [destination]. The program you have given is quite complex, and my data backup is not backup for server usage. It is backup from external hard disk to PC local drive and from PC local drive to external hard disk. Hope you get what I mean, is there any simple way to write robocopy batch file without using variables?

                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: Robocopy Command
                « Reply #9 on: September 03, 2016, 09:16:17 AM »
                or u can do this

                :: Robocopy.exe must be somewhere in PATH - Already the case in newer versions of Windows
                ::
                :: Change variables below to suit your needs


                set SOURCE=%systemdrive%\temp
                set DEST=%systemdrive%\testdir
                set OPTS=/mir /np /w:3 /r:3
                set /a THREADS=%NUMBER_OF_PROCESSORS%

                This is just a warning that the /mir switch can destroy an entire hard drive worth of information if the paths are wrong.


                foxidrive



                  Specialist
                • Thanked: 268
                • Experience: Experienced
                • OS: Windows 8
                Re: Robocopy Command
                « Reply #10 on: September 03, 2016, 09:30:00 AM »
                The way you want to copy your files isn't clear so i have left the /e switch as you had it.

                I can't see why you had an error message but it seems pretty clear that the code you have shown is not the exact code you are using, so the error could be anything.

                If you want an exact copy of the source folder in the top two robocopy commands then replace /e with /mir but be very certain that there are no errors in typing all the path names.

                I'm not sure why you included the restartable mode switch but I removed that.

                There are pause commands after each robocopy line for testing purposes.
                 - any error message that appears will be caused by the command above the numbered pause prompt.

                Code: [Select]
                @echo off
                rem wait and retry times can be set to zero on local drives - at least I use it that way.
                set switches=/r:0 /w:0
                rem Copy folders and subdirectories.
                robocopy "C:\Users\Owner\Desktop\New folder" "K:\New folder" /e %switches%
                echo 1 & pause
                robocopy "C:\Users\Owner\Desktop\New folder (2)" "K:\New folder2" /e %switches%
                echo 2 & pause
                rem Copy specified files in the folders and subdirectories folders.
                robocopy "C:\Users\test\Documents" "D:\Outlook" "Bowling Competition 2015 (Inter-Site).xlsx" %switches%
                echo 3 & pause

                Jiafu

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: Robocopy Command
                  « Reply #11 on: September 04, 2016, 08:29:58 AM »
                  @foxidrive, if I will to transfer using point to point which means from 1 PC to another PC. How should I write the program and to ensure that admin rights has been given to do the transfer using robocopy?

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: Robocopy Command
                  « Reply #12 on: September 04, 2016, 05:43:23 PM »
                  What error message do you see when you try your code?

                  I will point out that you did state you were using a local drive and it's not a good idea to give incorrect details when asking for programming code.

                  Jiafu

                    Topic Starter


                    Rookie

                    • Experience: Beginner
                    • OS: Windows 7
                    Re: Robocopy Command
                    « Reply #13 on: September 04, 2016, 07:18:48 PM »
                    @foxidrive, this is the code that I have written and save as .bat:

                    @echo off

                    rem Copy folders and subdirectories.
                    robocopy "C:\Users\tlex06\Documents" "F:\Documents" /e /w:1 /r:5 /zb

                    echo.

                    :exit

                    @pause

                    I receive the following error  as I was doing data transfer from my PC local drive to external harddisk.

                    The filename, directory name, or volume label syntax is incorrect, and this error prompt me 3 times. I also notice that not all the data are been transfer.

                    When I transfer data using point to point, I receive the following error: Accessing source directory Logon failure: unknown user name or bad password, thus data are unable to transfer

                    I have set both PC to static ip address

                    Please advise on how to resolve the issue.

                    Geek-9pm


                      Mastermind
                    • Geek After Dark
                    • Thanked: 1026
                      • Gekk9pm bnlog
                    • Certifications: List
                    • Computer: Specs
                    • Experience: Expert
                    • OS: Windows 10
                    Re: Robocopy Command
                    « Reply #14 on: September 04, 2016, 09:16:22 PM »
                    May I but in?
                    The command
                    Quote
                    robocopy "C:\Users\tlex06\Documents" "F:\Documents" /e /w:1 /r:5 /zb
                    can be simplified and the errors might go away.