Skip to main content

How to Copy a Directory in CMD

• 1 min read
cmd command-prompt directory xcopy copy windows

You can use the following syntax in Command Prompt (CMD) to copy a directory and its contents:

xcopy source_directory destination_directory /E /I

This example will copy the specified directory and all its contents to the new location.

Note: The /E flag copies all subdirectories, including empty ones, and the /I flag assumes the destination is a directory if it does not exist.

The following example shows how to use this syntax in practice.

Example: Copying a Directory in CMD

Suppose that we want to copy a directory named my_app to my_demoApp in the following path:

C:\Users\admin\Documents\cmd_script

We can type the following command to copy the directory:

xcopy C:\Users\admin\Documents\cmd_script\my_app C:\Users\admin\Documents\cmd_script\my_demoApp /E /I
```powershell
The following screenshot shows how to use this syntax in practice:

!Copy a directory in cmd

We can see that the directory **my_app** and all its contents (**scheduler.bat** file) have been copied to **my_demoApp** in **C:\Users\admin\Documents\cmd_script**.

## Conclusion

We can use the **xcopy** command followed by the path to copy any directory and its contents on the system.

You can find more topics about Active Directory tools and PowerShell basics on the [ActiveDirectoryTools](https://activedirectorytools.net/) home page.