How To Use Robocopy To Transfer Files
When moving files on a Windows machine it is tough to find a better tool than Robocopy. Robocopy is a robust file copying program built into Windows.
Robocopy is able to copyin large datasets or lots of files across volumes, and is a great tool for backing up data, it has the ability to resume copies if interrupted, has a plethora of options, creates robust logs during copying, and is not limited by the “Maximum Path Length Limitation“ that plague other coping applications.
In this video we will explore using Robocopy to move files from our source folder to our destination folder using the more common methods.
Prerequisites include: Run PowerShell as Administrator and as a user with sufficient rights to all directories
In this demonstration we’ll see how to utilize Robocopy in powershell first you'll need to make sure that you've opened PowerShell or command line as an administrator before you get started to get help with Robocopy type. Robocopy forward slash. Question mark this will display all switch options and their functions. Robocopy with all its power is fairly simple to use. We need to provide it with basic information like a source path where you want the files to come from and a destination path. This is where you want the files to go. Robocopy now has all the information it needs to copy all the files located in our source to our destination. Robocopy quickly moved all of our files to the destination directory. You'll notice, however, that it only moved the files located in the source location root and did not move any of the folders or sub folders or files. If we want Robocopy to copy all files and folders in our source location will need only add the Ford Slash E which instructs Robocopy to copy all files in sub directories, including empty ones to our destination folder to our command. This method would be great for moving files and directories to a backup location. All the files in the source location remain. It's a direct copy to the destination folder we’re able to do a lot more than just copy files from one folder to another with Robocopy warning using any of these next switches can or will delete the files from the source folder after they are copied or change the directory structure in the destination folder. Please triple check that you're using the correct switch for the outcome that you have in mind. By adding the forward slash move command. We can move the files and directories deleting from the source when we're finished copying. As you can see in test folder all the directories and files were moved we can also see that the test folder underscore 01 was deleted from the C temp folder, giving us a complete and clean move. If we remove the E from this command. It changes the command completely Forward Slash MOV moves source files and folders removing files after finishing copying but leaving the source folder and structure intact, we now see that the contents of test folder 01 has been moved to test folder 02. But the folders that were in test folder 01 remain there. However, now empty. another very useful switch is the forward slash Mir. Any changes made in the source directory will be mirrored in the destination directory. This is a lot like just a straight copy to test this, let's create a new file in our source folder. And then run our command. Much like copy it moves the file from the source to the destination folder. The difference between the Mirror Command and the copy command is that if I. Delete this file from the source folder and then run the command again. It also deletes it from our destination folder. If the files in our source folder were very important or we wanted to make sure that the directory and file properties were carried over to the destination folder, we would only need to add a few more switches to this Robocopy Command. The first would enable Robocopy's ability to restart if its connection was lost. We do that. By using the ZB switch. ZB enables restart mode and if access is denied. This option will use a backup mode to move the file to the destination folder. Next D copy with DAT switch will make sure that our directory's maintain the data attribute and timestamps. The copy all switch copies all file info. The data the attributes the time stamp. The security NTFS ACL info. The owner info and any auditing info. The switch R with the value of 5. This will tell Robocopy to retry 5 times if it runs into any issues. The switch W with the value of 10 instructs Robocopy to wait 10 seconds between each of its 5 retries and finally to create those robust logs during copying we’ll need to tell it where to save our log files here. I use the variable that way. It's easy for me to define at the top of my script with these 3 variables and this one line of code. I can copy all the files from my source location to my destination location and if I would need to either mirror that directory. Or move those files in one way or another. I would only need to add that to the end. From here, I could at any of my move switches or my mirror switch depending on the needs at the time, creating the variable with easily recognizable names for the Robocopy Command helps ensure that we don't accidentally mix up our source and destination paths. With our copy option being one of the few things we need to change in the command line itself. This Robocopy Command in this powerShell script will be usable should we need it in the future. Thank you for watching.