Advertisement
Yesideez

picrenamer.py

Jun 5th, 2024 (edited)
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | Source Code | 0 0
  1. # File  : picrenamer.py
  2. # Author: Zeb/Slipstream
  3. # Date  : 5-Jun-2024
  4.  
  5. from sys import argv
  6. from glob import glob
  7. from pathlib import Path
  8. from PIL import Image
  9. #from PIL.ExifTags import TAGS
  10. from os import rename
  11.  
  12. blnCommit=False #Check for the parameter to make the changes
  13. if len(argv)>1 and argv[1]=="commit":
  14.   blnCommit=True
  15.  
  16. intCount=0
  17. lstFiles=glob("*.[j|J][p|P][g|G]")
  18. lstFiles.sort()
  19.  
  20. for i in lstFiles:
  21.   im=Image.open(i)
  22.   tmp=im.getexif()
  23.   dt=tmp[306].split(" ") #extract the date time into a list
  24.   tm=dt[1].split(":")    #extract the date into a list
  25.   dt=dt[0].split(":")    #extract the time into a list
  26.   strAfter=f"{dt[0]}-{dt[1]}-{dt[2]} {tm[0]}-{tm[1]}-{tm[2]}.jpg"
  27.   file=Path(strAfter)
  28.   if blnCommit:
  29.     if file.exists():
  30.       print(f"ERR: File '{strAfter}' exists")
  31.     else:
  32.       #print(f"Rename '{i}' to '{strAfter}'")
  33.       rename(i,strAfter)
  34.       intCount+=1
  35.   else:
  36.     print(f" '{i}' to '{strAfter}'")
  37.  
  38. if blnCommit:
  39.   print(f"Files: {intCount}/{len(lstFiles)}")
  40. else:
  41.   print(f"Files: {len(lstFiles)} (nothing has been changed)")
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement