Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
- Get-ChildItem ./ | Sort-Object $ToNatural |
- Foreach-Object { $lastFileName = '0' } {
- $fileName = [System.IO.Path]::GetFileNameWithoutExtension($_)
- $expectedName = [string]([int]$lastFileName + 1)
- if ($expectedName -ne $fileName) {
- Rename-Item -Path $_ -NewName ($expectedName + [System.IO.Path]::GetExtension($_))
- }
- $lastFileName = $expectedName
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement