Created
January 3, 2022 13:36
-
-
Save rettinghaus/4f296218958f8af314c174c4c3e1a717 to your computer and use it in GitHub Desktop.
change 0-based file names to 1-based file names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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