Skip to content

Instantly share code, notes, and snippets.

@ReDestroyDeR
Created April 15, 2023 22:13
Show Gist options
  • Save ReDestroyDeR/4e3aceeb8c482468183dffffa7c2865d to your computer and use it in GitHub Desktop.
Save ReDestroyDeR/4e3aceeb8c482468183dffffa7c2865d to your computer and use it in GitHub Desktop.
Smol rename script
import os
listing = list(sorted(os.listdir('./timelapse')))
def get_num(x: str):
return int(x.split("-")[0])
prefix = "000"
suffix = "-main.png"
startNum = get_num(listing[0])
prevNum = startNum
print('Starting with: ' + str(startNum))
for filename in listing[1:]:
numPart = get_num(filename)
if (prevNum + 1 == numPart):
prevNum = numPart
continue
delta = numPart - prevNum - 1
print('Dropped frames! ' + str(prevNum) + ' to ' + str(numPart) + ' delta ' + str(delta))
for num in range(prevNum, startNum - 1, -1): # If we start from beggining, we may accidently override existing files
os.rename('./timelapse/' + prefix + str(num) + suffix, './timelapse/' + prefix + str(num + delta) + suffix)
print('Renamed ' + prefix + str(num) + suffix + ' to ' + prefix + str(num + delta) + suffix)
prevNum = numPart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment