Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import shutil
- input_directory = '/Users/Kristina/PycharmProjects/testing/input'
- output_directory = '/Users/Kristina/PycharmProjects/testing/output'
- for filename in os.listdir(input_directory):
- match_result = re.match('(.+)(\d{2})-(\d{2})-(\d{4})(.+)', filename)
- if (match_result):
- filename_first_part = match_result.group(1)
- month = match_result.group(2)
- day_of_month = match_result.group(3)
- year = match_result.group(4)
- filename_last_part = match_result.group(5)
- new_filename = filename_first_part + year + '.' + month + '-' + day_of_month + filename_last_part
- full_source_path = os.path.join(input_directory, filename)
- full_destination_path = os.path.join(output_directory, new_filename)
- print('Copying file ' + full_source_path + ' to ' + full_destination_path)
- shutil.copy2(full_source_path, full_destination_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement