Apr 13 2023 04:25 PM
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.
Apr 14 2023 01:27 AM
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
Apr 16 2023 11:08 PM
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).
Apr 20 2023 03:03 PM