Created
June 20, 2020 11:54
-
-
Save rlaphoenix/b4d00fb7a18d2ed3a5aebdd2eff45c57 to your computer and use it in GitHub Desktop.
Dataset Helper - Renamer: Renames a bunch of png files based on filename integer-wise to start at 1
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 argparse | |
import glob | |
import os | |
import re | |
ArgParser = argparse.ArgumentParser() | |
ArgParser.add_argument("-i", "--input", help="Input folder", required=True) | |
args = ArgParser.parse_args() | |
for n, file_path in enumerate(sorted( | |
glob.glob( | |
pathname=os.path.join(args.input, "**", "*.png"), | |
recursive=True | |
), | |
key=lambda x: int(re.sub(r"\D", "", os.path.splitext(os.path.basename(x))[0])) | |
)): | |
new_file_path = os.path.join(os.path.dirname(file_path), f"{n+1}.png") | |
print(f"{file_path} -> {new_file_path}") | |
os.rename(file_path, new_file_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment