Forum Discussion
How do I promote the files from a subfolder into each parent folder for 1000+ folders
Hi DharmDevi
That should work
$Folders = Get-ChildItem -Directory C:\GIT_WorkingDir\PowerShellScripts\Techcommunity
Foreach ($Folder in $Folders)
{
Write-Host "Working on Folder: $($Folder.Name)" -foregroundColor Green
$Files = Get-ChildItem -File $Folder.FullName -Recurse
Foreach ($File in $Files)
{
$FileName = $File.Name
$FilePath = $File.VersionInfo.FileName
$TargetFolder = $Folder.FullName
Write-Host "Move-Item: $FilePath > $TargetFolder\$FileName" -foregroundColor Cyan
Move-Item -Path $FilePath -Destination "$TargetFolder\$Filename"
}
}
Regards
Andres Bohren
- DharmDeviApr 17, 2023Copper Contributor
Hi, Thank you very much for this.
I discovered I don't have the correct rights to my system to be able to do this. I think I will have to look for the CMD version (as I have access to this and not powershell).
- Andres-BohrenApr 20, 2023Steel ContributorIf you don't have the rights it won't work with cmd imho