copy - File Copying

Maintained on

The copy command is the basic command for copying files.

It suits lightweight tasks such as duplicating a single file, copying many files with wildcards, and concatenating text files.

However, copy cannot copy whole folders. To copy folders and subfolders, use xcopy or robocopy.

Quick Reference

GoalCommand
Copy a filecopy a.txt D:\Backup\
Copy under a new namecopy a.txt b.txt
Overwrite without promptingcopy /y a.txt D:\Backup\
Copy by extensioncopy *.txt D:\Backup\
Merge text filescopy a.txt+b.txt c.txt
Copy a whole folderxcopy /e /i src dst (not possible with copy)

Basics of the copy Command

The commonly used form is:

copy [options] <source> <destination>

More precisely, you can join multiple input files with +, and specify /A or /B on both the input and output sides.

copy [/d] [/v] [/n] [/y | /-y] [/z] [/a | /b] <source> [/a | /b] [+ <source2> [/a | /b] ...] [<destination> [/a | /b]]

Main Options

OptionDescription
/dDecrypts encrypted files while copying
/vVerifies the copy after writing
/nUses a short 8.3 file name when possible
/ySuppresses the overwrite confirmation prompt
/-yAlways shows the overwrite confirmation prompt
/zCopies over a network in restartable mode
/aTreats the file as a text file
/bTreats the file as a binary file
/A and /B are a bit special

/A and /B do not mean file attributes. They mainly affect how files are handled when concatenating text, and you can usually ignore them for a simple file copy.

Basic File Copy

This example copies report.txt to D:\Backup.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy report.txt D:\Backup\report.txt
1 file(s) copied.
C:\users\user>

If you specify only a folder as the destination, the file is copied with the same name.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy report.txt D:\Backup\
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門

Quote paths that contain spaces

Enclose paths with spaces in double quotes, for example copy "C:\My Files\report.txt" "D:\Daily Backup\report.txt".

Controlling the Overwrite Prompt

If a file with the same name already exists, you may be asked for confirmation.

Use /y to overwrite without a prompt.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy /y report.txt D:\Backup\report.txt
1 file(s) copied.
C:\users\user>

To always be asked, specify /-y.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy /-y report.txt D:\Backup\report.txt
Overwrite D:\Backup\report.txt? (Yes/No/All):
Batch files often need /y

In automated processing, a confirmation prompt stops the script. When you intentionally want to overwrite in a batch file, add /y to be safe.

Copying Multiple Files with Wildcards

You can copy files in bulk by extension or part of the name.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy *.log D:\Archive\
app.log
error.log
access.log
…
12 file(s) copied.
C:\users\user>

Concatenating Text Files

copy can also join multiple text files into one.

copy /a part1.txt + part2.txt merged.txt

This example joins part1.txt and part2.txt in order and saves the result as merged.txt.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>copy /a intro.txt + body.txt + footer.txt article.txt
intro.txt
body.txt
footer.txt
1 file(s) copied.
C:\users\user>
Watch line breaks and encoding in the result

If a file does not end with a line break, its last line is joined with the first line of the next file. Also, concatenating UTF-8 files that have a BOM leaves the BOM in the middle of the result, which can cause garbled characters. With /a, reading also stops at the first Ctrl+Z (EOF character), and an EOF character may be appended to the output.

Use /b for Binary Files

For images, executables, and archives, use /b to treat them as binary.

copy /b part1.bin + part2.bin merged.bin

What copy Cannot Do

copy is for files. It is not suited to copying whole folders.

To copy folders

To copy folders and subfolders together, use xcopy or robocopy.

Troubleshooting

  • If you see “The system cannot find the file specified.”, check the source path and file name, including the extension.
  • If the destination folder does not exist, the folder name may be treated as a file name. When the destination is a folder, add a trailing \ to make that explicit.
  • If you see “Access is denied.”, check write permissions and whether another program has the file open.

Practical Examples

Duplicating a File in a Batch File

backup_one_file.cmd
@echo off
setlocal

set "SRC=%USERPROFILE%\Documents\report.txt"
set "DST=%USERPROFILE%\Documents\backup\report.txt"

copy /y "%SRC%" "%DST%"

endlocal
exit /b

Copying to a Network Share

copy /z report.txt \\Server\Share\report.txt

With /z, restartable mode is used for the copy over the network.

Summary

  • copy is the basic command for copying files
  • Use /y to skip the overwrite prompt
  • Wildcards let you handle multiple files
  • It can also concatenate text and binary files
  • To copy whole folders, use xcopy or robocopy instead of copy

Practice Questions

Practice Problem

Which is the correct way to duplicate file1.txt as file2.txt?

Choose one answer.

  1. copy file1.txt file2.txt
  2. copy /source file1.txt /destination file2.txt
  3. copy file1.txt > file2.txt

Practice Problem

Which option skips the overwrite confirmation for an existing file?

Choose one answer.

  1. copy /y
  2. copy /a
  3. copy /z
#Command Prompt #Batch File #File Operations #Copy #Command