Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # File : picrenamer.py
- # Author: Zeb/Slipstream
- # Date : 5-Jun-2024
- from sys import argv
- from glob import glob
- from pathlib import Path
- from PIL import Image
- #from PIL.ExifTags import TAGS
- from os import rename
- blnCommit=False #Check for the parameter to make the changes
- if len(argv)>1 and argv[1]=="commit":
- blnCommit=True
- intCount=0
- lstFiles=glob("*.[j|J][p|P][g|G]")
- lstFiles.sort()
- for i in lstFiles:
- im=Image.open(i)
- tmp=im.getexif()
- dt=tmp[306].split(" ") #extract the date time into a list
- tm=dt[1].split(":") #extract the date into a list
- dt=dt[0].split(":") #extract the time into a list
- strAfter=f"{dt[0]}-{dt[1]}-{dt[2]} {tm[0]}-{tm[1]}-{tm[2]}.jpg"
- file=Path(strAfter)
- if blnCommit:
- if file.exists():
- print(f"ERR: File '{strAfter}' exists")
- else:
- #print(f"Rename '{i}' to '{strAfter}'")
- rename(i,strAfter)
- intCount+=1
- else:
- print(f" '{i}' to '{strAfter}'")
- if blnCommit:
- print(f"Files: {intCount}/{len(lstFiles)}")
- else:
- print(f"Files: {len(lstFiles)} (nothing has been changed)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement