I am writing a PS script that takes a flattened directory structure, finds the pdfs, and copies them to a renamed folder with a sequential name, ie, 1.pdf, 2.pdf, etc. What I want to do is make this accommodate nested directories in the Location, but I am a bit of a novice with PS and don't know how to do this while maintaining the count variable.
Here is what I have:
Set-Location -path "C:\Users\mmcintyre\Desktop\test pdfs"
Get-ChildItem *.pdf |
ForEach-Object -Begin { $count = 1 } -Process {
Copy-Item -LiteralPath $_ -Destination ".\renamed\$count.pdf";
Write-Host "Renamed $($_.fullname) to $count.pdf"
$count++
}
Any help would be greatly appreciated.
Edit: As I was on Powershell =< 2.0, I needed to use the following in addition to the Recurse:
Get-ChildItem -Path .\* -Include *.pdf -Recurse |
which works now. Hope this helps someone else.