a
, b
, and c
are files in a folder ~\Source\x\
, and b
, d
, and f
are files in a folder ~\Destination\x\
. I want files a
and c
to be copied to ~\Destination\x\
, and for ~\Destination\x\b
to be replaced with ~\Source\x\b
.
~\Destination\x\
should have a
, b
, c
, d
, and f
.
Use Copy-Item Command to Copy Files Recursively in PowerShell. We usually run into situations where we have many subfolders in the parent folder, which files we'd like to copy over. Using the -Recurse parameter on Copy-Item will look in each subfolder and copy all files and folders in each recursively.
Copy-Item cmdlet is used to copy a directory by passing the path of the directory to be copied and destination path where the folder is to be copied.
Select the file you want to copy by clicking on it once. Right-click and pick Copy, or press Ctrl + C . Navigate to another folder, where you want to put the copy of the file. Click the menu button and pick Paste to finish copying the file, or press Ctrl + V .
Copy-Item with Force looks like what you are looking for.
[string]$sourceDirectory = "C:\Source\*" [string]$destinationDirectory = "C:\Destination\" Copy-item -Force -Recurse -Verbose $sourceDirectory -Destination $destinationDirectory
Copy-item never delete extra files or folders in destination, but with
-force
it will overwrite if file already exists
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With