サブディレクトリを含むファイルとディレクトリをコピーします。
For examples of how to use this command, see Examples.
Syntax
xcopy <Source> [<Destination>] [/w] [/p] [/c] [/v] [/q] [/f] [/l] [/g] [/d [:MM-DD-YYYY]] [/u] [/i] [/s [/e]] [/t] [/k] [/r] [/h] [{/a | /m}] [/n] [/o] [/x] [/exclude:FileName1[+[FileName2]][+[FileName3]]] [{/y | /-y}] [/z] [/b] [/j] [/compress]
Parameters
Parameter | Description |
---|---|
<源> | Required. コピーするファイルの場所と名前を指定します。 このパラメーターには、ドライブまたはパスを含める必要があります。 |
[<目的地>] | コピーするファイルのコピー先を指定します。 このパラメーターには、ドライブ文字とコロン、ディレクトリ名、ファイル名、またはこれらの組み合わせを含めることができます。 |
/w | 次のメッセージを表示し、応答を待ってからファイルのコピーを開始します: キーを押してファイルのコピーを開始します。 |
/p | 各コピー先ファイルを作成するかどうかを確認するメッセージが表示されます。 |
/c | Ignores errors. |
/v | コピー先ファイルに書き込まれる各ファイルを検証して、コピー先ファイルがソース ファイルと同じであることを確認します。 |
/q |
xcopy メッセージの表示を抑制します。 |
/f | コピー中のソース ファイル名とコピー先ファイル名を表示します。 |
/l | コピーするが、ファイルをアクティブにコピーしないファイルの一覧を生成します。 |
/g | Creates decrypted destination files when the destination doesn't support encryption. |
/d [:MM-DD-YYYY] | 指定した日付以降に変更されたソース ファイルのみをコピーします。 If you don't include a MM-DD-YYYY value, xcopy copies all source files that are newer than existing destination files. このコマンド ライン オプションを使用すると、変更されたファイルを更新できます。 |
/u | Copies files from source that exist on destination only. |
/i | If source is a directory or contains wildcards and destination doesn't exist, xcopy assumes destination specifies a directory name and creates a new directory. 次に、 xcopy 指定したすべてのファイルを新しいディレクトリにコピーします。 By default, xcopy prompts you to specify whether destination is a file or a directory. |
/s | ディレクトリとサブディレクトリが空でない限り、コピーします。 If you omit /s, xcopy works within a single directory. |
/e | 空の場合でも、すべてのサブディレクトリをコピーします。 Use /e with the /s and /t command-line options. |
/t | サブディレクトリ構造 (つまりツリー) のみをコピーし、ファイルはコピーしません。 To copy empty directories, you must include the /e command-line option. |
/k | Copies files and retains the read-only attribute on destination files if present on the source files. 既定では、 xcopy は読み取り専用属性を削除します。 |
/r | 読み取り専用ファイルをコピーします。 |
/h | 非表示のファイル属性とシステム ファイル属性を持つファイルをコピーします。 既定では、 xcopy は非表示またはシステム ファイルをコピーしません |
/a | Copies only source files that have their archive file attributes set. /a doesn't modify the archive file attribute of the source file. For information about how to set the archive file attribute by using attrib, see Related links. |
/m | Copies source files that have their archive file attributes set. Unlike /a, /m turns off archive file attributes in the files that are specified in the source. For information about how to set the archive file attribute by using attrib, see Related links. |
/n | NTFS の短いファイル名またはディレクトリ名を使用してコピーを作成します。 /n is required when you copy files or directories from an NTFS volume to a FAT volume or when the FAT file system naming convention (that is, 8.3 characters) is required on the destination file system. The destination file system can be FAT or NTFS. |
/o | ファイルの所有権と随意アクセス制御リスト (DACL) 情報をコピーします。 |
/x | Copies file audit settings and system access control list (SACL) information (implies /o). |
/exclude:FileName1[+[FileName2]][+[FileName3]( )] | ファイルの一覧を指定します。 少なくとも 1 つのファイルを指定する必要があります。 各ファイルには、ファイル内の個別の行の各文字列を含む検索文字列が含まれています。 いずれかの文字列がコピーするファイルの絶対パスの一部と一致する場合、そのファイルはコピー対象から除外されます。 For example, specifying the string obj will exclude all files underneath the directory obj or all files with the .obj extension. |
/y | 既存のコピー先ファイルを上書きすることを確認するメッセージが表示されないようにします。 |
/-y | 既存のコピー先ファイルを上書きすることを確認するメッセージが表示されます。 |
/z | 再起動可能モードでネットワーク経由でコピーします。 |
/b | ファイルの代わりにシンボリック リンクをコピーします。 このパラメーターは Windows Vista® で導入されました。 |
/j | バッファリングせずにファイルをコピーします。 非常に大きなファイルに推奨されます。 このパラメーターは、Windows Server 2008 R2 で追加されました。 |
/compress | 必要に応じて、ファイル転送中にネットワーク圧縮を要求します。 |
/[- ]sparse |
コピー処理中におけるファイルのスパース状態の保持を有効または無効にします。 If both parameters are specified, /-sparse overrides /sparse. |
/noclone | 最適化としてのブロック複製を試行しません。 |
/? | コマンド プロンプトにヘルプを表示します。 |
Remarks
Using /z
コピー フェーズ中に接続が失われた場合 (たとえば、サーバーがオフラインになると接続が切断された場合)、接続を再確立した後に再開されます。 /z also displays the percentage of the copy operation completed for each file.
Using /y in the COPYCMD environment variable.
You can use /y in the COPYCMD environment variable. You can override this command by using /-y on the command line. 既定では、上書きを求められます。
暗号化されたファイルのコピー
暗号化されたファイルを EFS をサポートしていないボリュームにコピーすると、エラーが発生します。 最初にファイルを復号化するか、EFS をサポートするボリュームにファイルをコピーします。
Appending files
ファイルを追加するには、変換先に 1 つのファイルを指定しますが、ソースには複数のファイルを指定します (つまり、ワイルドカードまたは file1+file2+file3 形式を使用)。
Default value for destination
If you omit destination, the
xcopy
command copies the files to the current directory.Specifying whether destination is a file or directory
If destination doesn't contain an existing directory and doesn't end with a backslash (), the following message appears:
Does <Destination> specify a file name or directory name on the target(F = file, D = directory)?
ファイルまたはファイルをファイルにコピーする場合は、F キーを押します。 ファイルまたはファイルをディレクトリにコピーする場合は、D キーを押します。
You can suppress this message by using the /i command-line option, which causes
xcopy
to assume that the destination is a directory if the source is more than one file or a directory.Using the
xcopy
command to set archive attribute for destination filesxcopy
コマンドは、この属性がソース ファイルに設定されたかどうかにかかわらず、アーカイブ属性が設定されたファイルを作成します。 For more information about file attributes and attrib, see Related links.xcopy
とdiskcopy
の比較サブディレクトリにファイルを含むディスクがあり、別の形式のディスクにコピーする場合は、
xcopy
の代わりにdiskcopy
コマンドを使用します。diskcopy
コマンドはトラックごとにディスク をコピーするため、ソース ディスクとコピー先ディスクの形式は同じである必要があります。xcopy
コマンドには、この要件はありません。 ディスク イメージの完全なコピーが必要な場合を除き、xcopy
を使用します。メモリ不足エラー
ファイル名のパスが 255 文字を超えるファイルまたはフォルダーをコピーするために
xcopy
を実行すると、"メモリ不足" エラーが発生する可能性があります。の終了コード
xcopy
To process exit codes returned by
xcopy
, use the ErrorLevel parameter on the if command line in a batch program. For an example of a batch program that processes exit codes using if, see Related links. 次の表に、各終了コードと説明を示します。Exit code Description 0 エラーなしでファイルがコピーされました。 1 コピーするファイルが見つかりませんでした。 2 ユーザーが Ctrl キーを押しながら C キーを押して、 xcopy
を終了しました。4 初期化エラーが発生しました。 メモリまたはディスク領域が不足しているか、コマンド ラインに無効なドライブ名または無効な構文を入力しました。 5 ディスク書き込みエラーが発生しました。
Examples
1. To copy all the files and subdirectories (including any empty subdirectories) from drive A to drive B, type:
xcopy a: b: /s /e
2. To include any system or hidden files in the previous example, add the /h command-line option as follows:
xcopy a: b: /s /e /h
3. To update files in the \Reports directory with the files in the \Rawdata directory that have changed since December 29, 1993, type:
xcopy \rawdata \reports /d:12-29-1993
4. To update all the files that exist in \Reports in the previous example, regardless of date, type:
xcopy \rawdata \reports /u
5. To obtain a list of the files to be copied by the previous command (that is, without actually copying the files), type:
xcopy \rawdata \reports /d:12-29-1993 /l > xcopy.out
xcopy.out ファイルには、コピーされるすべてのファイルが一覧表示されます。
6. To copy the \Customer directory and all subdirectories to the directory \\Public\Address on network drive H:, retain the read-only attribute, and be prompted when a new file is created on H:, type:
xcopy \customer h:\public\address /s /e /k /p
7. To issue the previous command, ensure that xcopy
creates the \Address directory if it doesn't exist, and suppress the message that appears when you create a new directory, add the /i command-line option as follows:
xcopy \customer h:\public\address /s /e /k /p /i
8. You can create a batch program to perform xcopy
operations and use the batch if command to process the exit code if an error occurs. たとえば、次のバッチ プログラムでは、 xcopy
のソースパラメーターと宛先パラメーターに置き換え可能なパラメーターが使用されます。
@echo off
rem COPYIT.BAT transfers all files in all subdirectories of
rem the source drive or directory (%1) to the destination
rem drive or directory (%2)
xcopy %1 %2 /s /e
if errorlevel 4 goto lowmemory
if errorlevel 2 goto abort
if errorlevel 0 goto exit
:lowmemory
echo Insufficient memory to copy files or
echo invalid drive or command-line syntax.
goto exit
:abort
echo You pressed CTRL+C to end the copy operation.
goto exit
:exit
上記のバッチ プログラムを使用して、C:\Prgmcode ディレクトリとそのサブディレクトリ内のすべてのファイルを B ドライブにコピーするには、次のように入力します。
copyit c:\prgmcode b:
The command interpreter substitutes C:\Prgmcode for %1 and B: for %2, then uses xcopy
with the /e and /s command-line options. If xcopy
encounters an error, the batch program reads the exit code and goes to the label indicated in the appropriate IF ERRORLEVEL statement, then displays the appropriate message and exits from the batch program.
9. This example copies all the non-empty directories, plus files with the associated file extension after the asterisk symbol.
xcopy .\toc*.yml ..\..\Copy-To\ /S /Y
rem Output example.
rem .\d1\toc.yml
rem .\d1\d12\toc.yml
rem .\d2\toc.yml
rem 3 File(s) copied
In the preceding example, this particular source parameter value .\toc*.yml copies the same 3 files even if its two path characters .\ were removed. However, no files would be copied if the asterisk wildcard was removed from the source parameter, making it just .\toc.yml.