user9579474
user9579474

Reputation: 11

Search file in a directory and replace it with powershell scripting

I have two directories A and B. A is having few *.dll files.B is also having *.dll files. Now I have to pick file from directory A and search in directory B, if found I will replace the file in B directory with the file in directory A. How I can write powershell script for this.

Upvotes: 0

Views: 172

Answers (2)

user6811411
user6811411

Reputation:

IMO Replace / xcopy / robocopy will be faster or more efficient.

In powershell there are thousand ways to do it, here is one:

$DirA = "C:\Windows\System32\"
$DirB = "Q:\Test\2018\03\31\"
Get-ChildItem -Path $DirA -Filter *.dll |
  Where-Object { Test-Path (Join-Path $DirB $_.Name) } |
    Copy-Item -Destination (Join-Path $DirB $_.Name)

Upvotes: 1

Tanveer Badar
Tanveer Badar

Reputation: 5522

You don't need powershell for that.

robocopy src dest /XX

will suffice.

Upvotes: 0

Related Questions