Search code examples
powershellmovesubdirectory

Powershell - Move files 1 folder deeper


I'm looking to move a large set of pdf files one folder deeper.

The current file structure is:
[Reference Code]\[file].pdf
and i'm looking to move the files to:
[Reference Code]\April 18\[file].pdf

if i recall correctly this could be done in linux with mv */*.pdf */April 18/*.pdf but a solution for windows seems to be a bit more complicated


Solution

  • $rootPath = "C:\"
    $moveTo = "C:\April 18"
    
    foreach ($pdfFile in (Get-ChildItem $rootPath | Where-Object {$_.Extension -eq ".pdf"}))
    {
        Move-Item -Path $pdfFile.FullName -Destination "$moveTo\$($pdfFile.Name)"
    }
    

    Like this?