Skip to content

Instantly share code, notes, and snippets.

@marcduiker
Last active August 9, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcduiker/2199c57cc616c418a510a9bd6c25977d to your computer and use it in GitHub Desktop.
Save marcduiker/2199c57cc616c418a510a9bd6c25977d to your computer and use it in GitHub Desktop.
Incrementally rename files for ffmpeg
$prefix="frame_"
$files = Get-ChildItem "<Path where the pngs are>" -Filter *.png | Sort-Object
$fileCount = 0
$files |
Foreach-Object {
$fileCount++
$currentFileNumber = [int]$_.BaseName.Substring($prefix.Length)
if ($currentFileNumber -ne $fileCount) {
$newFileFormat = "$prefix{0:d4}.png" -f $fileCount
Rename-Item $_.FullName $newFileFormat
Write-Output "$newFileFormat (renamed)"
}
else {
$orig = $_.Name + " (orig)"
Write-Output $orig
}
}
Write-Output "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment