Skip to content

Instantly share code, notes, and snippets.

@rettinghaus
Created January 3, 2022 13:36
Show Gist options
  • Save rettinghaus/4f296218958f8af314c174c4c3e1a717 to your computer and use it in GitHub Desktop.
Save rettinghaus/4f296218958f8af314c174c4c3e1a717 to your computer and use it in GitHub Desktop.
change 0-based file names to 1-based file names
import os
path = "YourPath"
_ext = ".png"
for (dirpath, dirnames, filenames) in os.walk(path):
if '0000' + _ext in filenames:
print(f"{dirpath} has zero-based index")
for filename in list(reversed(filenames)):
if filename[4:] == _ext:
os.rename(os.path.join(dirpath, filename), os.path.join(dirpath, str(int(filename[:4]) + 1).zfill(4) + _ext))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment