Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. def validFile(file):
  2. fup = file.upper()
  3. good_extensions = ['.JPG', '.TIF', '.WAV']
  4. filename, file_extension = os.path.splitext(file)
  5. return os.path.isfile(file) and file_extension in good_extensions
  6.  
  7. def dateAndFilename(file):
  8. try:
  9. date_formatted = pulling_metadata_date(file)
  10. except KeyError:
  11. print('Images Do not Contain Date Information in their METADATA')
  12. date_formatted = "NO-DATE
  13. return date_formatted, file
  14.  
  15. def File_Date_Organiser(absolute_path):
  16. os.chdir(absolute_path)
  17. print(os.listdir('.'), os.path.abspath(os.curdir))
  18.  
  19. valid_files = filter(validFile, os.listdir)
  20. dates_and_filenames = map(dateAndFilename, valid_files)
  21. unique_dates = set([d for d, _ in dates_and_filenames])
  22. formatted_dates = ["{}-{}".format(d[:4], d[5:7]) for d in unique_dates]
  23.  
  24. for date in formatted_dates:
  25. if not os.path.exists(date):
  26. os.mkdir(date)
  27.  
  28. for number, (date, fn) in enumerate(dates_and_filenames.items()):
  29. shutil.move(file, '{}'.format(folder_name))
  30. print('Complete')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement