Forum Discussion
DavidMAshworth
Feb 02, 2023Copper Contributor
Having trouble moving multiple folders up a level
Hi all, I have a requirement to change a file structure for a client. Basically they want all files within an "FYxx" folder to be moved one level up while maintaining the folder structure. I ...
Vinod_5
Feb 05, 2023Copper Contributor
Hi DavidMAshworth,
Good day!
According to your requirement the below script worked for me with my data.
I used a different logic as I was unable to fetch required data from get-childitem in for loops as provided in your script.
Please check with my script and let me know the result.
I will be happy to try once again. Thank you.
#Define the path to the parent folder
$parentFolder = "C:\SP"
cd $parentFolder
$subFolders = Get-childItem -path $parentFolder - Directory
$fyFolders = Get-childItem - path $subFolders - Recurse | where-object {$_. PSIsContainer - and $_.Name -like "*FY*"}
$count = $fyFolders.count
For ($i=0; $i -lt $count; $i++)
{
Move-Item - path $fyFolders[$i]. FullName - Destination $parentFolder
}
Good day!
According to your requirement the below script worked for me with my data.
I used a different logic as I was unable to fetch required data from get-childitem in for loops as provided in your script.
Please check with my script and let me know the result.
I will be happy to try once again. Thank you.
#Define the path to the parent folder
$parentFolder = "C:\SP"
cd $parentFolder
$subFolders = Get-childItem -path $parentFolder - Directory
$fyFolders = Get-childItem - path $subFolders - Recurse | where-object {$_. PSIsContainer - and $_.Name -like "*FY*"}
$count = $fyFolders.count
For ($i=0; $i -lt $count; $i++)
{
Move-Item - path $fyFolders[$i]. FullName - Destination $parentFolder
}
- Vinod_5Feb 16, 2023Copper Contributor