PoshTip #17 – Copy files to a new location
To copy a file from one folder to another, you can use the Copy-Item cmdlet :
1 |
Copy-Item -Path C:\folder1\file1.txt -Destination c:\folder2\file1.txt |
You can copy and rename the file with the same cmdlet :
1 |
Copy-Item -Path C:\folder1\file1.txt -Destination c:\folder2\file1-renamed.txt |
You can test if the destination folder exist with Test-Path cmdlet :
1 2 3 4 5 6 |
C:\> Test-Path C:\folder1\ True C:\> Test-Path C:\folder2\ True C:\> Test-Path C:\folder3\ False |