From aae6a67a3b8cb0b8353b0aa4f16bc14c5e458e26 Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Wed, 20 Sep 2023 11:08:17 -0400 Subject: [PATCH] Feat: Start to add Directory indexing for file transfers --- mediacopy/file_copy.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mediacopy/file_copy.py b/mediacopy/file_copy.py index 6e52344..654597b 100644 --- a/mediacopy/file_copy.py +++ b/mediacopy/file_copy.py @@ -18,6 +18,7 @@ INGEST_DIR = filedialog.askdirectory() PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/' # TODO: Add dircectory traversal file_list = [] +dir_list = {} def compare_and_move(): @@ -25,12 +26,14 @@ def compare_and_move(): for root, d_names, f_names in os.walk(INGEST_DIR, topdown=False): for file in f_names: file_name = os.path.join(root, file) - print(file_name) + # print(file_name) # Debugging file_list.append(file_name) - print(root, d_names, f_names) - print(file_list) - print(len(file_list)) - # process_files(file_list) + # print(root, d_names, f_names) # Debugging + # print(file_list) # Debugging + # print(len(file_list)) # Debugging + + process_files(file_list) + print(dir_list.keys()) # remove_empty_directories(INGEST_DIR) @@ -67,11 +70,14 @@ def process_files(file_list): year = str(parsed_date.year) month = str(parsed_date.month).zfill(2) day = str(parsed_date.day).zfill(2) - destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY, - year, month, day, filename) + destination_path = "%s%s/%s" % (PHOTO_LIBRARY, year, month) + destination = "%s/%s" % (destination_path, filename) + if not destination in dir_list.keys(): + dir_list[destination_path] = [] + dir_list[destination_path].append(cur_file) # print(destination) - print("We want to move %s to %s%s/%s/%s." % - (filename, PHOTO_LIBRARY, year, month, day)) + print("We want to move %s to %s%s/%s." % + (filename, PHOTO_LIBRARY, year, month)) # check if the directory exists if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))): @@ -80,15 +86,15 @@ def process_files(file_list): if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))): print("We couldn't find your directory, matching year and month") os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month))) - if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))): - print("We couldn't find your directory, matching year month and day") - os.makedirs(os.path.join(PHOTO_LIBRARY, - str(year), str(month), str(day))) + # I'm not sure that I care about the day anymore # + # if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))): + # print("We couldn't find your directory, matching year month and day") + # os.makedirs(os.path.join(PHOTO_LIBRARY, + # str(year), str(month), str(day))) # We should be copying, creating a source and destination hash # comparing the files and then deleting the source - print() - print("Copying %s to %s" % (cur_file, destination)) + print("\nCopying %s to %s" % (cur_file, destination)) copy2(cur_file, destination) if filecmp.cmp(cur_file, destination) == True: print("%s and %s are a match. Time to delete %s" %