Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy content of a folder to another specific folder using powershell?

Tags:

powershell

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.

like image 646
Deepak Avatar asked Mar 30 '16 13:03

Deepak


People also ask

How do I copy files from one directory to another in PowerShell?

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.

How do I copy an entire folder in PowerShell?

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.

How do I copy content from one folder to another?

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 .


1 Answers

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

like image 194
Eric S Avatar answered Sep 19 '22 13:09

Eric S