Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def validFile(file):
- fup = file.upper()
- good_extensions = ['.JPG', '.TIF', '.WAV']
- filename, file_extension = os.path.splitext(file)
- return os.path.isfile(file) and file_extension in good_extensions
- def dateAndFilename(file):
- try:
- date_formatted = pulling_metadata_date(file)
- except KeyError:
- print('Images Do not Contain Date Information in their METADATA')
- date_formatted = "NO-DATE
- return date_formatted, file
- def File_Date_Organiser(absolute_path):
- os.chdir(absolute_path)
- print(os.listdir('.'), os.path.abspath(os.curdir))
- valid_files = filter(validFile, os.listdir)
- dates_and_filenames = map(dateAndFilename, valid_files)
- unique_dates = set([d for d, _ in dates_and_filenames])
- formatted_dates = ["{}-{}".format(d[:4], d[5:7]) for d in unique_dates]
- for date in formatted_dates:
- if not os.path.exists(date):
- os.mkdir(date)
- for number, (date, fn) in enumerate(dates_and_filenames.items()):
- shutil.move(file, '{}'.format(folder_name))
- print('Complete')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement