How to Copy Folder With Its Contents in Batch Script

MD Aminul Islam Feb 02, 2024
  1. Method 1: Copy Folder With Its Contents Using the XCOPY
  2. Method 2: Copy Folder With Its Contents Using the ROBOCOPY
How to Copy Folder With Its Contents in Batch Script

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.

MD Aminul Islam avatar MD Aminul Islam avatar

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

Related Article - Batch Copy