BlueRey

photos.py

Oct 12th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. '''
  2. photos.py by Daniel Admon
  3.  
  4. This script is made to make my life easier.
  5. I'm a photographer that shoot in RAW and JPEG.
  6. why JPEG and RAW ? because RAW is a large file and its slower then JPEG
  7. so its faster to view and organize photos with JPEG,
  8. and when i'm editing the photos i'm using the RAW files.
  9.  
  10. The script check if there are RAW file without the JPG file and delete the RAW file.
  11. '''
  12. import os, shutil
  13.  
  14. dir = os.getcwd()
  15. #dir = input("Please type path to the folder:  ")
  16. #dir = "C:\\Users\DA\Desktop\motorcity"
  17.  
  18. deldir = os.path.join(dir,"del"); count = 0
  19.  
  20. if not os.path.exists(dir):
  21.     print(f"Error: directory \"{dir}\" doesn't exist.")
  22.     exit()
  23.  
  24. if not os.path.exists(deldir):
  25.     os.makedirs(deldir)
  26.  
  27. for cr2 in os.listdir(dir):
  28.     if cr2.endswith(".CR2"):
  29.         crfile = os.path.join(dir,cr2)
  30.         if os.path.isfile(os.path.join(dir,cr2.split(".")[0] + ".JPG")) == False:
  31.             delfile = os.path.join(deldir,cr2)
  32.             if os.path.isfile(delfile)  == False:
  33.                 print(f"Moving file \"{crfile}\" to {deldir}")
  34.                 shutil.move(crfile,deldir)
  35.                 count += 1
  36.             else:
  37.                 print(f"Error: file \"{cr2}\" already exist in {deldir}")
  38.  
  39. print(f"total moved: {count}")
Add Comment
Please, Sign In to add comment