copy - File Copying
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
| Goal | Command |
|---|---|
| Copy a file | copy a.txt D:\Backup\ |
| Copy under a new name | copy a.txt b.txt |
| Overwrite without prompting | copy /y a.txt D:\Backup\ |
| Copy by extension | copy *.txt D:\Backup\ |
| Merge text files | copy a.txt+b.txt c.txt |
| Copy a whole folder | xcopy /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
| Option | Description |
|---|---|
/d | Decrypts encrypted files while copying |
/v | Verifies the copy after writing |
/n | Uses a short 8.3 file name when possible |
/y | Suppresses the overwrite confirmation prompt |
/-y | Always shows the overwrite confirmation prompt |
/z | Copies over a network in restartable mode |
/a | Treats the file as a text file |
/b | Treats the file as a binary file |
/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.
If you specify only a folder as the destination, the file is copied with the same name.

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
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.
To always be asked, specify /-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.
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.
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 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
@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
copyis the basic command for copying files- Use
/yto skip the overwrite prompt - Wildcards let you handle multiple files
- It can also concatenate text and binary files
- To copy whole folders, use
xcopyorrobocopyinstead ofcopy