Search code examples
arrayspowershellmove

How to move array from parent folder to new destination, while keeping same folder structure?


$srcRoot = (Get-ChildItem -Path 'C:\Unsigned Items\*\*\* Archive' -Directory).FullName

Above is what I am using to get all of the files under multiple subfolders with the same name of "* Archive".

For example:

C:\Users\Nick\Documents\City 1\City 1 Archive
C:\Users\Nick\Documents\City 2\City 2 Archive
C:\Users\Nick\Documents\City 3\City 3 Archive

I am wanting to move all of the files within each of the "archive" subfolders to a different location like C:\Users\Documents\Archive

I want to retain the folder structure and to also keep in place the folder structure in the parent folder.


Solution

  • You will need to create the folder structure prior to moving the files. Then you can loop through each item and do a $_.Replace('C:\Unsigned Items','C:\Users\Nick\Documents') as the target path for the move.