Skip to content

XCOPY Windows Command Guide

The Windows xcopy command is a powerful tool for copying files and directories with advanced options like filtering and preserving attributes. With its flexibility and efficiency, xcopy is a popular choice for users looking to replicate data quickly and effectively. This guide will walk you through the various parameters and uses of the xcopy command, helping you master this essential tool in your Windows workflow.

XCOPY Syntax:

Terminal window
xcopy Source [Destination] [/w] [/i] [/s] [/e] [/p] [/c] [/q] [/h] [/r] [/k] [/d] [/y] [/f] [/l] [/t] [/u] [/g] [/j] [/b] [/v] [/z] [/n] [/o] [/x] [/a] [/m] [/it] [/exclude:FileName1[+FileName2][+...]] [/excludefile:FileName]

Options:

OptionDescription
/wPrompts you to press a key before starting
/iIf destination does not exist and copying more than one file, assumes that destination must be a directory
/sCopies directories and subdirectories except empty ones
/eCopies all subdirectories including empty ones
/pPrompts during copying
/cContinues copying even if errors occur
/qDoes not display file names during copying
/hCopies hidden and system files
/rOverwrites read-only files
/kCopies files without changing the read-only attribute
/dCopies only files changed on or after the specified date
/ySuppresses prompting to confirm you want to overwrite an existing destination file
/fDisplays full source and destination file names
/lDisplays files that would be copied
/tCreates directory structure, but does not copy files.
/uCopies only files that already exist in destination
/gEnables copying encrypted files to a destination that does not support encryption
/jCopies with unbuffered I/O. Recommended for very large files
/bCopies symbolic links versus the target
/vVerifies each new file
/zCopies networked files in restartable mode
/nCopies using the generated short names
/oCopies file ownership and discretionary access control list information
/xCopies file audit settings (implies /o)
/aCopies only source files modified on or after the specified date
/mCopies only archive files and resets them
/itExcludes system and hidden files from the copy
/exclude:Excludes files that match specified names or patterns
/excludefile:Specifies a list of files containing strings and wildcards to exclude from the copying process

Parameters:

ParameterDescription
SourceSpecifies the file(s) to copy
DestinationSpecifies the location to copy files to

XCOPY Command Samples:

Copy a File to Another Location

Terminal window
xcopy file.txt C:\DestinationFolder\

Copies the file “file.txt” to the “DestinationFolder” on the C drive.

Copy a Directory and All Its Contents

Terminal window
xcopy C:\SourceFolder\ D:\DestinationFolder\ /s /e

Copies all files and subdirectories from “SourceFolder” to “DestinationFolder,” including empty directories.

Copy Files with a Specific Extension

Terminal window
xcopy *.pdf D:\PDFFiles\

Copies all PDF files from the current directory to the “PDFFiles” folder on the D drive.

Copy Files and Prompt Before Overwriting

Terminal window
xcopy C:\SourceFolder\*.txt E:\Backup\ /p

Copies all text files from “SourceFolder” to the “Backup” folder on the E drive, prompting before overwriting any existing files.

Copy Files and Retain Source File Attributes

Terminal window
xcopy C:\SourceFolder\*.* D:\Destination\ /k

Copies all files from “SourceFolder” to the “Destination” folder, retaining the attributes of the source files.

Copy Files and Create a Log File

Terminal window
xcopy C:\SourceFolder\ D:\DestinationFolder\ /s /e > copylog.txt

Copies files and directories from “SourceFolder” to “DestinationFolder” and creates a log of the copy process in the “copylog.txt” file.

Copy Files Only if Different in Size or Timestamp

Terminal window
xcopy C:\SourceFolder\ D:\DestinationFolder\ /d

Copies files from “SourceFolder” to “DestinationFolder” only if they have changed (different in size or timestamp).

How do I use xcopy in Windows?

To use the xcopy command in Windows, execute the following command:

Terminal window
xcopy source_path destination_path

What is the difference between xcopy and copy in Windows?

The xcopy command in Windows is used for copying multiple files, directories, and subdirectories in a single command, while the copy command is used for copying individual files.

Terminal window
copy file.txt destination_path

How can I include subdirectories when using xcopy in Windows?

To copy subdirectories along with files using xcopy in Windows, include the /s option in the command:

Terminal window
xcopy source_path destination_path /s

How can I force overwrite existing files with xcopy in Windows?

To force overwrite existing files without prompting when using xcopy in Windows, include the /y option in the command:

Terminal window
xcopy source_path destination_path /y

How can I copy hidden or system files with xcopy in Windows?

To copy hidden or system files when using xcopy in Windows, include the /h option in the command:

Terminal window
xcopy source_path destination_path /h

Can I exclude specific files or folders when using xcopy in Windows?

Yes, you can exclude specific files or folders when using xcopy in Windows by listing them after the source_path and destination_path in the command:

Terminal window
xcopy source_path destination_path /exclude:file_list.txt

Applications of the XCOPY Command

  • Copy files and directories
  • Copy files with specified attributes
  • Copy files and directories recursively
  • Copy files and directories including subdirectories
  • Copy files and directories with or without prompting
  • Copy files and directories with or without overwriting existing files
  • Synchronize the contents of two directories
  • Copy files across network locations
  • Copy files with progress indicator
  • Exclude specific files or directories from being copied