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
  • 5,299
  • 7
  • 16
  • 35
DaveM
  • 1
  • 1
  • 2
  • Look at the `/LEV:n` argument. it does what you describe – Frank Thomas Jan 11 '22 at 18:11
  • Thank You Frank! :) OK then i will try this with Easy ROBOCOPY. or maybe CMD!? – DaveM Jan 11 '22 at 23:00
  • Sorry to say it did not work! it still copies all folders below the source. Despite the /LEV:n switch. – DaveM Jan 14 '22 at 22:19
  • when you use terms like below and above, there is a bit of ambiguity. do you imagine directory trees as Pines with the root at the top, or Shrubberies, with the roots at the bottom? /LEV controls how many levels it will recurse into. its not clear whether you mean to copy three levels deep from the root, or recurse in three levels before starting to copy. – Frank Thomas Jan 14 '22 at 22:33
  • No worries. ok that is the opposite of what LEV does. I'd probably write a powershell script to call robocopy in a loop, cd'ing into the level2 directory with each itteration, and copying their files/subdirs. – Frank Thomas Jan 14 '22 at 23:16
  • I am sorry for my bad explanation. I edited the original post above. Hope it is a little clearer! :) – DaveM Jan 14 '22 at 23:21
  • OK, That explanes why it is hard to get any search results on google! lol. Well i will have to look into this exciting part of computing! :) Anyway, thank you so much Frank!. – DaveM Jan 14 '22 at 23:23
  • [windows - Move all files from multiple subfolders into the parent folder - Super User](https://superuser.com/questions/999922/move-all-files-from-multiple-subfolders-into-the-parent-folder/999966) – w32sh Jan 16 '22 at 04:38

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
  • 8,704
  • 1
  • 15
  • 28