Copy Directory From Command Line [Step by Step]

By | March 27, 2022

Windows provides 2 command-line tools for copying files/directories. Copying files from one folder to another can be accomplished with the copy command. A complete folder cannot be copied to another place on the disk. We can do this with Xcopy. Here’s how to copy an entire directory along with all subdirectories and files.
Copy Directory From Command Line [Step by Step]

Xcopy command to copy folders and subfolders –

Xcopy /E /I SourceFolder DestinationFolder

Consider the case when we need to copy a directory called C:/dir1/sourcedir into a destination called D:\data\destinationdir.

To copy the entire source directories to D:/data/destination, run the following command:

Xcopy /E /I C:\dir1\sourcedir D:\data\destinationdir

The absolute path of the folders can also be used in the above command considering the current directory.

Copy Directory From Command Line –

Need to Know the Command:

Copy empty subfolders to the destination using /E.

When the destination is a file/folder, no prompt is displayed /E. This step is not necessary if you include the trailing '/' in the destination folder, as below.

Xcopy /E C:\dir1\sourcedir D:\data\destinationdir\

In order to use the /E, one does not need the /S option. This ensures that subfolders, as well as the original folder, are copied to the new destination.

Frequently Ask Questions:

Question: Does XCOPY copy folders?

Answer: Make a copy of files and directories to another folder. In contrast to COPY, Additional switches allow you to specify both the destination and source of XCOPY. Copy files modified on or after /D:mm-dd-yyyy.

Read: Windows Copy Command Syntax & Examples [CMD]

Leave a Reply

Your email address will not be published. Required fields are marked *