I try to move all files of extension .wav from 400 different folders inside a certain root folder, to their subfolders called 'Stems'. Meaning that each of those 400 folders inside the root folder have a subfolder called 'Stems'.
$Dir = 'F:\PRODUCTION\Complete Projects\*'
Get-ChildItem -Path $Dir -File -Filter '*.wav' |
ForEach-Object {
$Dest = "$($_.DirectoryName)\*\Stems"
If (!(Test-Path -LiteralPath $Dest))
{New-Item -Path $Dest -ItemType 'Directory' -Force}
Move-Item -Path $_.FullName -Destination $Dest
}
When I select for variable $dir a specified project folder and remove the * from the $dest$ variable, as shown below, it does move the .wav files correctly to the 'Stems' subfolder.
$Dir = 'F:\PRODUCTION\Complete Projects\Project 392 - Woodland\'
Get-ChildItem -Path $Dir -File -Filter '*.wav' |
ForEach-Object {
$Dest = "$($_.DirectoryName)\*\Stems"
If (!(Test-Path -LiteralPath $Dest))
{New-Item -Path $Dest -ItemType 'Directory' -Force}
Move-Item -Path $_.FullName -Destination $Dest
}
However, I would like to be able to do this at once for different folder names, instead of 400 times per specified folder.
Any suggestions?