0

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

2 Answers 2

1
$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?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the answer, that worked really nicely and gave a good example for me to build off
1

One possibility:

$rootDir = "Reference Code"

Get-ChildItem -Path "$rootDir\*.pdf" -File |
    ForEach-Object {
        Move-Item $_.FullName -Destination "$rootDir\April 18\$($_.Name)"
    }

Note that this will fail if folder April 18 doesn't exist.

1 Comment

Thanks for the option, i should have specified that i was looking for the script to create the folder, but this gives me a nice example to build from

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.