CMD Simulator
File Managementcopy

COPY Command – Duplicate Files in Windows Command Prompt

Master the COPY command to duplicate files and combine text files in Windows CMD. Complete guide with syntax, parameters, examples, and best practices.

Rojan Acharya·
Share

The COPY command is a Windows Command Prompt utility that duplicates files from one location to another, preserving the original source file. Use COPY to create file backups, duplicate files to multiple locations, combine text files into a single file, or copy files with wildcards for batch operations—all while maintaining the original source intact.

Whether you're a system administrator creating backup copies of configuration files, a developer duplicating project files across environments, or a power user organizing file collections, COPY provides reliable file duplication with verification options and flexible overwrite control. IT professionals rely on COPY for quick file backups, configuration management, and automated file distribution across enterprise networks.

This comprehensive guide covers COPY syntax, all parameters and switches, practical examples for common file duplication scenarios, troubleshooting tips for copy failures, related file management commands, and frequently asked questions. By the end, you'll confidently duplicate, combine, and distribute files from the command line for backup, deployment, and file management tasks.

What Is the COPY Command?

The COPY command is a fundamental file management tool in Windows Command Prompt that creates duplicates of files while leaving the source file intact. Unlike MOVE, which relocates files by deleting the source, COPY preserves the original, making it ideal for backups, distribution, and file duplication workflows.

COPY supports wildcards for copying multiple files matching patterns, can combine multiple text files into a single output file using the + operator, and offers options for verification and overwrite behavior. COPY works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), and is available in all Windows versions from MS-DOS through Windows 11, Windows Server 2022, and all enterprise editions.

The command's simplicity and reliability make it a staple in batch scripts, system administration tasks, and automated file management workflows. While more advanced tools like XCOPY and ROBOCOPY exist for complex scenarios, COPY remains the go-to choice for straightforward file duplication tasks.

COPY vs XCOPY vs ROBOCOPY

  • COPY: Duplicates individual files; cannot copy subdirectories; simple syntax; ideal for single-file or same-directory operations
  • XCOPY: Copies files and directory trees; supports subdirectories, attributes, and date filtering; better for directory structures
  • ROBOCOPY: Enterprise-grade robust copy; handles large-scale operations, retries on errors, preserves all attributes and permissions; ideal for backups and migrations

Use COPY for quick file duplication, XCOPY for directory trees, and ROBOCOPY for enterprise file operations.

Syntax

COPY [/A | /B] [/D] [/V] [/N] [/Y | /-Y] [/Z] source [/A | /B] [+ source [/A | /B] [+ ...]] [destination [/A | /B]]

Basic Parameters

ParameterDescription
sourceSpecifies the file(s) to copy (wildcards * and ? supported)
destinationSpecifies the directory or filename for the new file(s)
/YSuppresses prompting to confirm overwriting existing destination files
/-YPrompts for confirmation before overwriting existing destination files
/VVerifies that new files are written correctly by comparing with source
/AIndicates an ASCII text file (copies up to first EOF character)
/BIndicates a binary file (copies entire file including EOF markers)
/DAllows destination file to be created decrypted
/NUses short filenames (8.3 format) when copying
/ZCopies networked files in restartable mode

Advanced Parameters

ParameterDescription
+Combines multiple source files into a single destination file
/LDisplays files that would be copied without actually copying them

Default behavior: COPY treats files as binary (/B) by default. Use /A for text files when you need to stop copying at the first EOF (Ctrl+Z) character.

How to Use COPY Command

Copy a Single File

Duplicate a file to another directory, preserving the original:

COPY file.txt C:\Backup

This creates C:\Backup\file.txt while leaving the original file.txt in the current directory.

Copy and Rename a File

Copy a file to a new location with a different name:

COPY source.txt C:\Documents\renamed.txt

This creates C:\Documents\renamed.txt with the same content as source.txt.

Copy to Current Directory with New Name

Duplicate a file in the same directory with a different name:

COPY original.txt backup-original.txt

Useful for creating quick backups before editing files.

Copy Multiple Files with Wildcards

Use wildcards to copy all files matching a pattern:

COPY *.txt C:\TextFiles
COPY report*.docx C:\Reports
COPY data?.csv C:\Data
  • *.txt copies all files with .txt extension
  • report*.docx copies files starting with "report"
  • data?.csv copies files like data1.csv, data2.csv (? matches single character)

Copy Without Confirmation (/Y)

Use /Y to overwrite existing destination files without prompting:

COPY /Y source.txt C:\Destination

Essential for automated scripts and batch operations where manual confirmation isn't possible.

Copy with Confirmation (/-Y)

Use /-Y to prompt before overwriting each existing file:

COPY /-Y *.txt C:\Backup

Windows prompts "Overwrite C:\Backup\file.txt? (Yes/No/All)" for each conflicting file.

Combine Multiple Text Files

Use + to concatenate multiple text files into a single file:

COPY file1.txt + file2.txt + file3.txt combined.txt

This creates combined.txt containing the contents of file1, file2, and file3 in sequence. Works best with plain text files (TXT, LOG, CSV).

Advanced combination:

COPY *.log combined-logs.txt

Combines all .log files in the current directory into a single file.

Copy with Verification (/V)

Use /V to verify that the copied file matches the source:

COPY /V important.txt C:\Backup

The /V parameter compares the copied file to the source to ensure data integrity. Slower but recommended for critical files.

Copy All Files in Directory

Copy all files from one directory to another:

COPY C:\Source\*.* C:\Destination

The *.* wildcard matches all files regardless of name or extension.

Copy with Date Filtering

COPY doesn't have built-in date filtering, but you can combine with XCOPY for date-based copying:

XCOPY source destination /D:12-31-2025

This copies files modified on or after December 31, 2025.

Create Empty Files

Use COPY NUL to create empty files quickly:

COPY NUL empty.txt

Creates a zero-byte file named empty.txt. Useful for placeholder files or testing.

Common Use Cases

  1. Create file backups – Use COPY to duplicate important files to backup locations before editing, ensuring you can recover from mistakes or data corruption.

  2. Distribute files to multiple locations – Use COPY in batch scripts to place the same file in multiple directories for deployment or distribution.

  3. Copy files by type – Use COPY with wildcards to copy all files of a specific extension (e.g., COPY *.xlsx C:\Spreadsheets) for organization or archiving.

  4. Combine log files – Use COPY with + to merge multiple text or log files into a single file for analysis, reporting, or archiving.

  5. Duplicate configuration files – Use COPY to create copies of config files before editing, allowing easy rollback if changes cause issues.

  6. Batch file operations – Use COPY in scripts to automate file duplication tasks across multiple directories or systems.

  7. Create file templates – Use COPY to duplicate template files for new projects, documents, or configurations.

  8. Prepare files for processing – Use COPY to duplicate files to a working directory before processing, preserving originals.

  9. Deploy application files – Use COPY in deployment scripts to distribute application files, DLLs, or configuration files to target directories.

  10. Create versioned backups – Use COPY with date-stamped filenames in batch scripts for versioned backup workflows.

  11. Copy files to network shares – Use COPY to duplicate files to network drives for sharing, collaboration, or centralized storage.

  12. Merge data files – Use COPY with + to combine CSV, text, or data files for import into databases or analysis tools.

Tips and Best Practices

  1. Quote paths with spaces – Always enclose paths containing spaces in double quotes: COPY "My File.txt" "C:\My Documents". Without quotes, Windows interprets each word as a separate argument.

  2. Use /V for critical files – Enable verification with /V when copying important files to ensure data integrity: COPY /V critical.dat C:\Backup. This is slower but catches copy errors.

  3. COPY overwrites by default – Without /-Y, COPY overwrites destination files without prompting in scripts. Use /-Y to enable confirmation prompts for safety.

  4. Wildcards work with COPY – Use * (any characters) and ? (single character) for batch file operations: COPY *.txt C:\Backup copies all text files.

  5. COPY doesn't copy directories – For copying directories and subdirectories, use XCOPY source destination /E /I or ROBOCOPY source destination /E.

  6. Use COPY NUL for empty files – Create empty placeholder files with COPY NUL filename.txt. Faster than opening an editor.

  7. Combine with IF NOT EXIST – In scripts, avoid overwriting with: IF NOT EXIST dest.txt COPY src.txt dest.txt. This copies only if the destination doesn't exist.

  8. Verify source before copying – Use DIR source to verify files exist and check sizes before running COPY commands, especially with wildcards.

  9. Use /Y in automated scripts – Add /Y to suppress confirmation prompts in batch files and scheduled tasks: COPY /Y source dest.

  10. Combine files in order – When using + to combine files, specify them in the desired order: COPY header.txt + data.txt + footer.txt output.txt.

  11. Check available disk space – Before copying large files, verify destination has sufficient space with DIR or FSUTIL volume diskfree drive:.

  12. Use full paths in scripts – Specify complete paths in batch files to avoid ambiguity: COPY C:\Source\file.txt D:\Destination\file.txt.

Troubleshooting Common Issues

"Access is denied" Error

Problem: COPY fails with "Access is denied" when trying to copy files.

Cause: Insufficient permissions to read the source or write to the destination, destination file is read-only or in use, or attempting to copy to a protected system location.

Solution:

  • Run Command Prompt as Administrator for system locations
  • Close applications that might have the destination file open
  • Clear read-only attribute on destination: ATTRIB -R destination.txt
  • Verify you have write permissions on the destination directory
  • Check if antivirus software is blocking the operation

Prevention: Run CMD as Administrator when working with system directories. Verify permissions before copying to restricted locations.

"The file cannot be copied onto itself"

Problem: COPY displays "The file cannot be copied onto itself" error.

Cause: Source and destination paths resolve to the same file. This occurs when copying a file to the same directory with the same name.

Solution: Specify a different destination filename:

COPY file.txt file-backup.txt

Or copy to a different directory:

COPY file.txt C:\Backup\file.txt

Prevention: Always specify a different filename or destination directory when copying files.

Insufficient Disk Space

Problem: COPY fails with "Insufficient disk space" or "There is not enough space on the disk."

Cause: Destination drive doesn't have enough free space for the copied file(s).

Solution:

  • Check available space: DIR destination_drive:
  • Free up space by deleting unnecessary files
  • Copy to a different drive with more space
  • Use COMPACT /C to enable NTFS compression on the destination

Prevention: Verify available disk space before copying large files. Use FSUTIL volume diskfree C: to check free space programmatically in scripts.

COPY Doesn't Preserve Timestamps

Problem: Copied files have current date/time instead of original timestamps.

Cause: COPY updates the "Date Modified" timestamp to the copy time by default.

Solution: Use XCOPY to preserve timestamps:

XCOPY source destination /K /O

The /K parameter preserves attributes, and /O preserves ownership.

Alternative: Use ROBOCOPY for full timestamp and attribute preservation:

ROBOCOPY source_dir destination_dir filename /COPY:DAT

Prevention: Use XCOPY or ROBOCOPY instead of COPY when timestamp preservation is critical.

Combining Binary Files Produces Corruption

Problem: Using COPY file1.exe + file2.dll combined.exe creates a corrupted file.

Cause: The + operator is designed for text files. Binary files require exact byte-for-byte copying without text processing.

Solution: Don't combine binary files with COPY. For binary file operations, use specialized tools or programming languages.

For legitimate binary concatenation (rare), use /B:

COPY /B file1.bin + file2.bin combined.bin

Prevention: Only use + operator with plain text files (TXT, LOG, CSV). Use appropriate tools for binary file operations.

Wildcards Copy Unexpected Files

Problem: COPY *.txt C:\Backup copies more files than expected.

Cause: Wildcards match all files fitting the pattern, including hidden or system files.

Solution: Preview files before copying:

DIR *.txt

Then run COPY with the same pattern:

COPY *.txt C:\Backup

Use more specific wildcards: COPY report-*.txt instead of *.txt.

Prevention: Always use DIR with the same wildcard pattern to preview affected files before running COPY.

Related Commands

XCOPY – Advanced File and Directory Copy

XCOPY is an enhanced version of COPY that handles files, directories, and subdirectories with additional options for attributes, dates, and error handling.

Key advantages over COPY:

  • Copies entire directory trees with /E or /S
  • Preserves file attributes and timestamps
  • Supports date filtering (/D) to copy only newer files
  • Can exclude files with /EXCLUDE
  • Provides progress feedback for large operations

Example:

XCOPY C:\Source D:\Backup /E /I /Y

Copies all files and subdirectories from Source to Backup.

When to use: Copying directory structures, preserving attributes, or filtering by date.

ROBOCOPY – Robust File Copy

ROBOCOPY (Robust File Copy) is the enterprise-grade file copy tool with advanced features like retry logic, logging, and full attribute preservation.

Key advantages:

  • Automatic retry on errors (network interruptions, locked files)
  • Preserves all NTFS attributes, permissions, and timestamps
  • Multi-threaded copying for faster performance
  • Detailed logging and progress reporting
  • Mirror mode (/MIR) for exact directory replication

Example:

ROBOCOPY C:\Source D:\Backup /E /COPYALL /R:3 /W:5

Copies all files with full attributes, retries 3 times, waits 5 seconds between retries.

When to use: Enterprise backups, large-scale file migrations, or network file operations requiring reliability.

MOVE – Move Files (Delete Source)

MOVE relocates files by copying them to the destination and deleting the source. Use when you want to transfer files without creating duplicates.

Difference from COPY:

  • MOVE deletes the source after successful transfer
  • COPY preserves the source file

Example:

MOVE C:\Source\file.txt D:\Destination

When to use: Reorganizing file systems, moving files between drives, or freeing space by relocating files.

TYPE – Display File Contents

TYPE displays text file contents in the console. Use with COPY to verify file contents before or after copying.

Example:

TYPE source.txt
COPY source.txt backup.txt
TYPE backup.txt

Integration: Verify file contents match after copying text files.

COMP – Compare Files

COMP compares two files byte-by-byte to verify they're identical. Use after COPY to verify successful duplication.

Example:

COPY source.dat destination.dat
COMP source.dat destination.dat

If files match, COMP reports "Files compare OK."

When to use: Verifying critical file copies, especially when /V parameter isn't sufficient.

FC – File Compare

FC (File Compare) compares two files and displays differences. More detailed than COMP, showing actual differences in text files.

Example:

FC source.txt destination.txt

When to use: Comparing text files to identify differences after copying or editing.

Frequently Asked Questions

What does COPY /Y do?

COPY /Y suppresses confirmation prompts when overwriting existing files at the destination. Without /Y, COPY prompts "Overwrite [filename]? (Yes/No/All)" for each conflicting file in interactive sessions. Use /Y in automated scripts and batch files to avoid manual intervention: COPY /Y source.txt destination.txt.

How do I combine multiple files with COPY?

Use the + operator: COPY file1.txt + file2.txt + file3.txt output.txt. This concatenates the contents of file1, file2, and file3 into output.txt in the specified order. Works best with plain text files (TXT, LOG, CSV). For binary files, use /B: COPY /B file1.bin + file2.bin output.bin.

What is the difference between COPY and XCOPY?

COPY duplicates individual files and cannot copy subdirectories. XCOPY copies files, directories, and subdirectories with additional options like /S (subdirectories), /E (empty directories), /D (only newer files), and attribute preservation. Use COPY for simple file duplication; use XCOPY for directory trees and advanced filtering.

Can COPY copy directories?

No, COPY only copies files, not directories. To copy entire directories with subdirectories, use XCOPY source destination /E /I or ROBOCOPY source destination /E. COPY can copy multiple files to a directory but cannot replicate directory structures.

How do I verify a file copied correctly?

Use COPY /V source destination to enable verification. The /V parameter compares the copied file to the source to ensure data integrity. Alternatively, use COMP source destination after copying to manually verify files match byte-by-byte.

Why does COPY fail with "Access is denied"?

This error occurs when you lack permissions to read the source or write to the destination, the destination file is read-only or in use by another program, or you're copying to a protected system location. Solutions: Run CMD as Administrator, close programs using the file, clear read-only attributes with ATTRIB -R, or verify NTFS permissions with ICACLS.

Can I copy files to network drives?

Yes, COPY works with UNC network paths and mapped network drives: COPY file.txt \\server\share\folder or COPY file.txt Z:\folder for mapped drives. Ensure you have write permissions on the network share. For large network operations, use ROBOCOPY with /Z (restartable mode) for better reliability.

What does COPY /B do?

COPY /B treats files as binary, copying the entire file including EOF (End-of-File) markers. This is the default behavior. Use /A for ASCII text files when you want to stop copying at the first EOF character (Ctrl+Z). Binary mode is essential for executables, images, and non-text files.

How do I copy only newer files?

COPY doesn't have built-in date filtering. Use XCOPY instead: XCOPY source destination /D copies only files newer than existing destination files. For more advanced date filtering, use XCOPY source destination /D:MM-DD-YYYY to copy files modified on or after the specified date.

Can I copy hidden or system files?

Yes, COPY copies hidden and system files without requiring attribute changes. However, you must specify the exact filename or use wildcards that match the files. Use DIR /A:H to list hidden files before copying. COPY preserves file attributes in the destination.

How do I create a backup copy with timestamp?

Use a batch script with date/time variables:

@echo off
set timestamp=%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%
COPY file.txt file_%timestamp%.txt

This creates copies like file_20260213_1430.txt.

What happens if I interrupt COPY?

Interrupting COPY (Ctrl+C) stops the operation immediately. Partially copied files may exist at the destination but will be incomplete. For critical operations, use ROBOCOPY with /Z (restartable mode), which can resume interrupted copies.

Quick Reference Card

CommandPurposeExample Use Case
COPY file.txt C:\BackupCopy single fileCreate backup copy
COPY *.txt C:\DocsCopy multiple filesCopy all text files
COPY /Y src.txt dest.txtCopy without promptsAutomated scripts
COPY /V file.dat C:\BackupCopy with verificationCritical file backup
COPY file1+file2 out.txtCombine filesMerge log files
COPY NUL empty.txtCreate empty filePlaceholder file
COPY src.txt new.txtDuplicate & renameCreate file copy
COPY /-Y *.* C:\BackupCopy with confirmationSafe overwrite
COPY file.txt \\server\shareCopy to networkNetwork distribution
COPY /B *.bin combined.binCombine binary filesBinary concatenation

Try COPY Command Now

Ready to practice copying files? Use our Windows Command Simulator to run COPY commands safely in your browser. No installation required—practice COPY, wildcard operations, file combinations, and verification in a risk-free environment. Perfect for learning, training, or testing command sequences before running them on production systems.

Explore the full Commands Reference for more Windows CMD utilities, including file management (MOVE, DEL, REN), directory operations (MKDIR, RMDIR, CD), and system administration commands.

Summary

The COPY command is the essential Windows tool for duplicating files from the command line while preserving the original source. Use COPY to create file backups, copy files to multiple locations, duplicate files with wildcards for batch operations, or combine text files with the + operator.

Unlike MOVE, COPY preserves the original source file, making it ideal for creating backups, distributing files, and maintaining file redundancy. Combine /Y for silent overwriting in scripts, /V for verification of critical files, and wildcards for batch operations across multiple files.

Master COPY for file backup workflows, configuration management, file distribution, and automated file duplication tasks. For directory trees, use XCOPY; for enterprise operations with retry logic and full attribute preservation, use ROBOCOPY. Understanding when to use each tool ensures efficient and reliable file management in Windows environments.