Home > Software design >  How to move array from parent folder to new destination, while keeping same folder structure?
How to move array from parent folder to new destination, while keeping same folder structure?

Time:06-10

$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.

CodePudding user response:

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.

CodePudding user response:

All you would need to do is direct the move for the top folder:

Move-Item -Path "C:\Unsigned Items\*\*\* Archive"  -Destination "C:\Users\Documents\Archive" -WhatIf

This will retain the same folder structure after the move is completed.


remove the -WhatIf parameter when you've dictated those are the results you're after

  • Related