Forum Discussion
How do I promote the files from a subfolder into each parent folder for 1000+ folders
Hi,
I have the following folder hierarchy. There are over 1000 folders each for a different company. I need to put the files from the child folder, into each of the parent folders. (see example below).
Rather than cut and paste each of the files (there's like 16,000++ files) I would like to run a command or program to do this. But I can't find anything that will work.
(Folder) Company ABC
File A
File B
File C
(subfolder) Attachments
File Z
File Y
(Folder) Company DEF
File AA
File BB
File CC
(subfolder) Attachments
File ZZ
File YY
And what I would like it to look like is
(Folder) Company ABC
File A
File B
File C
File Z
File Y
(Folder) Company DEF
File AA
File BB
File CC
File ZZ
File YY
Thank you for your attention.
- Andres-BohrenSteel Contributor
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
- DharmDeviCopper 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-BohrenSteel ContributorIf you don't have the rights it won't work with cmd imho