DOS コマンドを目的別に調べることができる辞典

ホーム > DOS コマンド逆引き辞典 > コピー > 一部のディレクトリ、ファイルを除外してコピーする

DOS コマンド逆引き辞典

:: reverse dictionary ::

コピー

一部のディレクトリ、ファイルを除外してコピーする

一部のディレクトリおよびファイルを除外してコピーするには、xcopy コマンドに次の3つを指定して実行します。

≪ディレクトリ構造(サンプル)≫

D:ディレクトリ  F:ファイル

D C:\MyDir
├ F sample01.txt
├ F sample02.log
├ F sample03.log
├ F sample04.csv
├ D SubDir
│ ├ F sample02.txt
│ ├ F sample05.txt
│ ├ F sample06.log
│ └ F sample07.csv
└ D SubDir2
   └ F sample08.txt

≪除外対象を記述したファイル≫

C:\exclude.txt

sample01.txt
SubDir2
.csv
C:\>xcopy MyDir MyDir2 /exclude:exclude.txt /i /s
MyDir\sample02.log
MyDir\sample03.log
MyDir\SubDir\sample02.txt
MyDir\SubDir\sample05.txt
MyDir\SubDir\sample06.log
5 個のファイルをコピーしました

C:\>dir MyDir2 /b /s
C:\MyDir2\sample02.log
C:\MyDir2\sample03.log
C:\MyDir2\SubDir
C:\MyDir2\SubDir\sample02.txt
C:\MyDir2\SubDir\sample05.txt
C:\MyDir2\SubDir\sample06.log

exclude.txt に記述した文字列に一致するファイルとディレクトリを除外してコピーします。

▼ コマンド

xcopy 送り側 [受け側] [/exclude:除外対象記述ファイル]

xcopy コマンドに /exclude スイッチと除外対象記述ファイルを指定すると、そのファイルに記述した文字列に絶対パスの一部が一致するファイルとディレクトリを除外してコピーします。

除外対象記述ファイルには、除外の対象となる文字列を一行ずつ記述します。

例えば C:\sample.txt を除外する場合、.txtsample などの文字列を記述することで除外の対象になります。


除外対象記述ファイルは複数指定できます。
その際、ファイル名を + で区切ります。

≪除外対象を記述したファイル(2)≫

C:\exclude02.txt

sample02
sample06.log
C:\>xcopy MyDir MyDir3 /exclude:exclude.txt+exclude02.txt /i /s
MyDir\sample03.log
MyDir\SubDir\sample05.txt
2 個のファイルをコピーしました

C:\>dir MyDir3 /b /s
C:\MyDir3\sample03.log
C:\MyDir3\SubDir
C:\MyDir3\SubDir\sample05.txt

▼ 参照

注目キーワード ベスト5

  1. セキュリティ
  2. ホスティング
  3. レンタルサーバ
  4. ファイル復旧
  5. ハードディスク修復

コピー - copy -


ホーム > DOS コマンド逆引き辞典 > コピー > 一部のディレクトリ、ファイルを除外してコピーする

Copyright (C) 2005-2007 Noto Watabe. All rights reserved.
e-mail:wmh@always-pg.com