LoginSignup
2
0

[PowerShell]PowerShellでファイルをコピーする方法[Copy-Item]

Posted at

PowerShellでファイルをコピーする方法について

今回は、PowerShellでファイルのコピーをする方法、Copy-Itemコマンドを紹介します!

Copy-Itemの基本的な使い方

現在のPowerShell実行ポリシーを確認するには、次のコマンドを使用します。

Copy-Item -Path <source> -Destination <destination>

<source>: コピー元のファイルやフォルダーのパスを指定します。
<destination>: コピー先のフォルダーのパスを指定します。

例えば、Desktopフォルダー内のexample.txtをDocumentsフォルダーにコピーする場合、以下のようにコマンドを実行します。

Copy-Item -Path C:\Users\Username\Desktop\example.txt -Destination C:\Users\Username\Documents\

追加オプション

1.再帰的にコピー
フォルダー内のすべてのファイルやフォルダーを含めてコピーするには、-Recurseオプションを使用します。

Copy-Item -Path <source> -Destination <destination> -Recurse

2.ファイルの上書き
ファイルの上書きするには、-Forceオプションを使用します。

Copy-Item -Path <source> -Destination <destination> -Force

3.ログの記録
コピー操作をログに記録するには、-PassThruオプションを使用します。これにより、コピーされたファイルやフォルダーの情報が表示されます。

Copy-Item -Path <source> -Destination <destination> -PassThru

まとめ

今回は、PowerShellでファイルのコピーをする方法、Copy-Itemコマンドを紹介しました!
今回の記事を参考に、Copy-Itemコマンドを使用してみてください!

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0