1

Say I have a folder called '1' which has various folders in it. For example's sake to make it easy, say I have folders named 'A' through 'N' in alphabetical order inside that folder '1'. Then I have another folder called '2' in which it also has various folders in it, but it has, for example, only the folders 'B', 'C', 'F', 'K', and 'L'.

How can I automatically select the folders 'B', 'C', 'F', 'K', and 'L' in folder '1' and copy all of its contents/subfolders+its contents, etc. into folder '2' (but skip all existing files in '2' and just add the stuff that doesn't exist yet in '2' but '1' does have)?

1 Answer 1

2

This will get you started:

$targetdirs=Get-ChildItem folder2 | ? { $_.PSIsContainer }

foreach($dir in $targetdirs) { Copy-Item folder1\$dir folder2\$dir -Recurse}

There's only one problem, which I could not solve. The target folders get doubled. That is, you end up with Folder2\B\B instead of just Folder2\B. Maybe someone elase can improve on it.

1
  • I just removed from folder2\$dir the $dir part and it worked fine. Thanks
    – user152294
    May 10, 2019 at 12:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .