What is xcopy in batch file?

What is Xcopy command?

Xcopy, stands for extended copy, is a command that can copy multiple files or entire directory trees from one location to another. As an advanced version of the copy command, it has additional switches to specify both the source and the destination in detail. It is especially useful when copying files from CDROM to a hard drive because it will remove the read-only attribute automatically.

Xcopy command is available on most operating systems such as IBM PC DOS, MS-DOS, Windows and freeDOS. While being functionally replaced by a more powerful copy tool Robocopy, Xcopy is still included in Windows 10, and you can continue using it to copy folders and subfolders.

Can I copy folders and subfolders using Xcopy command?

What is xcopy in batch file?

I have a folder with a lot of subfolders and files in them. Now, I want to copy the folder to another location, but I don’t want to recreate directory structures. Can I use Xcopy command to copy the directory structure of the folder and subfolders to another location?

As we know, recreating directory structures can be a tedious and error-prone thing, especially if using the right-click method to create multiple structures and folders. So, you may want to copy folders and subfolders by Xcopy command directly. If you don’t know how to achieve it via Xcopy, keep reading to learn the detailed steps.

*If you want to customize your copy strategy more specifically, or copy folders while keeping historical versions for data protection purposes, you may consider using advanced method.

What is xcopy in batch file?

Copy folders and subfolders using Xcopy command in Windows 7/8/10/11

To move folders and subfolders in cmd, the most used command syntax would be:

xcopy [source] [destination] [options]

And there are plenty of options and switches for different demands. You can copy folders and subfolders including or excluding files from one location to another location by following the steps in different situations.

Situation 1. copy folders and subfolders and contents

1. Click Start and type cmd in the search box. Right-click Command Prompt from the result list and select Run as administrator. Or you can press Win + R to call up Run window, and type "cmd" in the textbox to directly run it.

2. Now, when you're in the Command Prompt, you can type Xcopy command as below to copy folders and subfolders including contents. For example, you want to copy “test” folder and its subfolders on C drive to D drive, type Xcopy command as:

Xcopy C:\test D:\test /E /H /C /I

What is xcopy in batch file?

  • /E – Copy subdirectories, including any empty ones.

  • /H - Copy files with hidden and system file attributes.

  • /C - Continue copying even if an error occurs.

  • /I - If in doubt, always assume the destination is a folder. e.g. when the destination does not exist.

Notes:

  • Xcopy will not copy open files.

  • Xcopy doesn’t display any progress or completed operations information when executed.

  • Remember that for folders with spaces in the name or folders larger than 8 characters in length, it is a good idea to put quotation marks around the path or you may get an error.

Situation 2. copy folders and subfolders without files

You can open the Command Prompt according to the steps shown above. Then, type the Xcopy command as below to copy folders and subfolders without files:

Xcopy Source Destination /T /E

  • /T - Copy the subdirectory structure, but not the files.

  • /E - Copy subdirectories, including any empty ones.

Situation 3. copy folders and subfolders with NTFS and Share permission

Sometimes, you may need to transfer the NTFS and Share permission together with your folders.

Once the Command Prompt is open, you can then type the following Xcopy command to copy all files and folders and retain its NTFS and Share permissions.

Xcopy Source Destination /O /X /E /H /K

  • /E - Copy folders and subfolders, including empty ones.

  • /H - Copy hidden and system files also.

  • /K - Copy attributes. Typically, Xcopy resets read-only attributes.

  • /O - Copy file ownership and ACL information.

  • /X - Copy file audit settings (implies /O).

Actually, there are many parameters of Xcopy command, and you can combine different parameters for different situations. But if there is a slight error in the command, the copy operation may fail, and even lead to data loss. Therefore, you must be very careful when using Xcopy command.

For users who are not familiar with the use of the command line, and want to copy files and folders easily, you can also use a handy backup software.

Advanced way to copy files or folders in Windows 7/8/10/11 flexibly

Xcopy essentially duplicates your folders to create an intact copy, and although it has some optional parameters, it is still difficult to do some advanced operations or requires carefully written syntax. 

For example, you may want to auto copy changed files to target directory, keep different versions of backups for accurate recovery, compress backup files to save storage space, etc. In these cases, AOMEI Backupper Standard is a free and reliable option for PCs running Windows 11/10/8.1/8/7/Vista/XP.

Copy options: It enables you to sync folders with original format & structure for direct use, or backup folders into image files in case of recovery needs.
Storage devices: It supports internal/external drive, USB flash drive, cloud, network share and NAS as target or destination storage.
Schedule options: It contains scheduled options to automate backup/sync task on regular basis, and you can perform incremental or differential backup to back up only changed data.
What's more: If you want to auto sync changed files from source to target in real time, or auto delete older versions of backups to save space, you can upgrade to Professional edition.

Step by step guide to copy files or folders via AOMEI Backupper

1. Download AOMEI Backupper Standard, install and launch it.

2. To copy folders with original format & structure, just select Sync > Basic Sync. If you want to backup folders into restorable image files, however, you can consider Backup options, which are better suited for backing up large data (like partitions, disks, system backup), or keeping different backup versions.

What is xcopy in batch file?

In advanced edition, you can enjoy 3 more practical sync modes:
Real-Time Sync: Sync changed files from source directory to target directory in real time.
Mirror Sync: Keep the contents in target directory exactly the same as the source directory.
Two-Way Sync: Make any changes in source or target directory be synced to the other side mutually.

3. Click Add Folder to specify the folder and click OK. You can add more folders by clicking the + button.

What is xcopy in batch file?

Note: After clicking Add Folder, you can open Filter Settings to set file inclusion/exclusion mask (available in Pro and above editions).

What is xcopy in batch file?

What is xcopy in batch file?

4. Select the destination path you want to copy files to. Internal hard drive, connected external hard drive, cloud drive, shared folder, and NAS are all available.

What is xcopy in batch file?

5. (Optional) Click Schedule Sync to enable it, and set a Daily/Weekly/Monthly task as you like.

What is xcopy in batch file?

6. Confirm all your settings and click Start Sync.

Verdict

You can copy folders and subfolders using Xcopy command by the steps shown above. However, many users say that copying failed due to Xcopy not working sometimes, or Xcopy does not copy all files. And in some cases, Xcopy halts because of “Insufficient Memory” error or invalid number of parameters. 

Therefore, using AOMEI Backupper to copy folders or files is a more reliable and convenient method. With only a few clicks, you can copy folders or files to your destination, and its useful features like incremental backup, USB plug in, etc. bring you much convenience.

If you want to backup files on any other computers without installation, use AOMEI Backupper Technician or Technician Plus to create a portable AOMEI Backupper. Just give it a shot! 

What is xcopy used for?

In computing, XCOPY is a command used on IBM PC DOS, MS-DOS, IBM OS/2, Microsoft Windows, FreeDOS, ReactOS, and related operating systems for copying multiple files or entire directory trees from one directory to another and for copying files across a network.

What is the difference between xcopy and copy?

XCOPY is similar to the COPY command except that it has additional switches to specify both the source and destination in detail. /D:mm-dd-yyyy Copy files changed on or after the specified date. If no date is given, copy only files whose source date/time is newer than the destination time.

How do I use xcopy files?

To move folders and subfolders in cmd, the most used command syntax would be:.
xcopy [source] [destination] [options].
Click Start and type cmd in the search box. ... .
Now, when you're in the Command Prompt, you can type Xcopy command as below to copy folders and subfolders including contents. ... .
Xcopy C:\test D:\test /E /H /C /I..

What is xcopy in powershell?

The xcopy command (as the name suggests) copies files from the source location to the destination location including files, folders, and recursively as well and it is quite different than the simple copy command because it supports the multiple switches including the copying the directory structure to the different ...