How to Copy Folder With Its Contents in Batch Script
-
Method 1: Copy Folder With Its Contents Using the
XCOPY
-
Method 2: Copy Folder With Its Contents Using the
ROBOCOPY
Copying files or folders are a common operation in our day-to-day computing activities.
In general, we copy a file or folder by selecting them and then right-click on the mouse and click on copy and paste it to the specified location. Also, we perform this task by using simple drag and drop.
But we also can do the same task by using Batch commands. This article will show how we can copy files from a folder to another location. We will discuss the topic using examples and explanations to make it easy to understand.
In Batch, the two most used commands can be used to copy the contents of a folder to another location. These are the the XCOPY
and ROBOCOPY
.
Method 1: Copy Folder With Its Contents Using the XCOPY
In our below example, we will illustrate how we can copy a folder with its content using the command XCOPY
. The general syntax for this purpose is XCOPY /E G:\YOUR_SOURCE G:\YOUR_DESTINATION
.
Let’s see an example of this method.
XCOPY /E G:\CopyFile\Source G:\CopyFile\Destination
After running the above command, you will see that all the contents inside your source folder are copied to the specified destination.
Method 2: Copy Folder With Its Contents Using the ROBOCOPY
In our example below, we will demonstrate how we can copy a folder with its content using the command ROBOCOPY
. The general syntax for this purpose is ROBOCOPY /E G:\YOUR_SOURCE G:\YOUR_DESTINATION
.
Let’s see an example of this method.
ROBOCOPY /E G:\CopyFile\Source G:\CopyFile\Destination
After running the above command, you will see that all the contents inside your source folder are copied to the specified destination.
Looking at the above commands, you will see that we used /E
with each command. The purpose of this option is to copy all the contents inside the folder, including directories and empty folders, to the destination folder.
Please note that the command provided in the article is written in Batch and only runnable to Windows Command Prompt.
Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.
LinkedIn