0

I have a folder named SCENERY on drive F (F:\SCENERY). It contains several folders: A, B, C... etc. I would like to merge the contents of A, B, C... etc to another folder on drive F named BASEFILES (F:\BASEFILES).

Is this possible?

PowerShell script used & output:

PS C:\Windows\system32> (Get-ChildItem 'F:\Scenery\*' -Directory).FullName |
ForEach-Object { Join-Path $_ '*' } |
Copy-Item -Destination 'F:\BaseFiles' -WhatIf
What if: Performing the operation "Copy Directory" on target "Item: F:\Scenery\XP11_HD_Mesh_V4\XP11_HD_Mesh_V4_+60-020-Europe Destination: F:\BaseFiles\XP11_HD_Mesh_V4_+60-020-Europe".
What if: Performing the operation "Copy Directory" on target "Item: F:\Scenery\XP11_HD_Mesh_V4\XP11_HD_Mesh_V4_+70+020-Europe Destination: F:\BaseFiles\XP11_HD_Mesh_V4_+70+020-Europe".
PS C:\Windows\system32>
Destroy666
  • 12,350
DaveM
  • 1
  • 1
  • 2

1 Answers1

0

If you want all the subfolders of F:\SCENERY, this PowerShell would work:

  • The destination folder, F:\BaseFiles, should be created prior to running this command.
(Get-ChildItem 'F:\Scenery\*' -Directory).FullName |
     ForEach-Object { Join-Path $_ '*' } |
         Copy-Item -Destination 'F:\BaseFiles' -Recurse

Edit:

Don't copy line-by-line, it's a single pipeline:

(Get-ChildItem 'F:\Scenery\*' -Directory).FullName | ForEach-Object { Join-Path $_ '*' } | Copy-Item -Destination 'F:\BaseFiles' -Recurse

  • To verify what will happen, run this version first:
(Get-ChildItem 'F:\Scenery\*' -Directory).FullName |
     ForEach-Object { Join-Path $_ '*' } |
         Copy-Item -Destination 'F:\BaseFiles' -Recurse -WhatIf
  • The -WhatIf parameter previews the operation without performing it.

Using aliases, the first command reduces to:

(gci 'F:\Scenery\*' -ad).FullName |
     % { Join-Path $_ '*' } |
         Copy -s 'F:\BaseFiles'
Keith Miller
  • 10,694
  • 1
  • 20
  • 35