Skip to content

Instantly share code, notes, and snippets.

@skarfie123
Last active September 12, 2020 12:05
Show Gist options
  • Save skarfie123/edf2731a79ff487d6e4d5cfaacd2b2fc to your computer and use it in GitHub Desktop.
Save skarfie123/edf2731a79ff487d6e4d5cfaacd2b2fc to your computer and use it in GitHub Desktop.
Quick script to add a suffix to all images in a folder:
# example: python "D:\Users\rahul\Documents\Python Scripts\image rename\imageRename.py" "D:\Users\rahul\Documents\Python Scripts\image rename\test_images" "blah"
# imageX.jpg --> imageX_blah.jpg
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("dir")
parser.add_argument("suffix")
args = parser.parse_args()
print(args.dir)
print(args.suffix)
answer = input("rename files in: "+args.dir+" with suffix: "+args.suffix+" are you sure? Y/N: ")
if answer.upper() != "Y":
exit()
print("Continuing")
for filename in os.listdir(args.dir):
src = args.dir + "\\" + filename
dst = args.dir + "\\" + filename.split(".")[0] + "_" + args.suffix + "." + filename.split(".")[1]
os.rename(src, dst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment