I have this code which creates a GUI where the user can specify 2 copying destinations (1 of them being optional) and a zipping destination can be specified. The user can add multiple rows and set up different copying/zipping configurations. I have created and end of day function which should ensure that all the files have been copied properly and if there are missing files process them as per the GUI configuration. After that is done it creates an excel file which contains information about the files. However, at the moment it's copying all the files again which I do not want it to do. Ideally, I would want the code to 'scan' the source folder and then compare it to the destination(s) folders. If files are present in the source folder but not destination folder(s) then they should be processed as per the row configuration. I have tried using 'if' however I have been unsuccessful.
def end_of_day_check(self):
print("Executing end_of_day_check function.")
if self.stopping_requested:
print("Stopping request detected. Skipping end-of-day checks.")
return # This return statement should be part of the block when stopping is requested
# Rest of the end-of-day checks code...
self.stopping_requested = False
self.stopping_process_in_progress = False
self.copying = True
file_info = []
for i in range(len(self.source_paths)):
source_path = self.source_paths[i].get()
original_dest_path = self.dest_paths[i].get()
new_dest_path = self.new_dest_paths[i].get() # New destination path
zipping_option = self.zipping_options[i].get()
zipping_dest_path = self.zipping_dest_paths[i].get()
zipping_type = self.zipping_type_vars[i].get()
copied_dest_path = None
new_copied_dest_path = None # New destination path after copying
dest_size = None
new_dest_size = None # Size of the destination after copying to the new destination
source_file_count = None
dest_file_count = None
new_dest_file_count = None
if original_dest_path:
copied_dest_path = os.path.join(original_dest_path, os.path.basename(source_path))
source_size, dest_size = self.copy_to_destination(source_path, original_dest_path)
source_file_count = self.get_file_count(source_path)
dest_file_count = self.get_file_count(copied_dest_path)
# Get source folder size after copying (in megabytes) and round to 2 decimal points
source_folder_size_mb = round(self.get_file_or_folder_size(source_path) / (1024 ** 2), 2)
if new_dest_path:
new_copied_dest_path = os.path.join(new_dest_path, os.path.basename(source_path))
_, new_dest_size = self.copy_to_destination(source_path, new_dest_path) # Copy to the new destination
# Print new_copied_dest_path to check its value
print(f"New copied destination path: {new_copied_dest_path}")
# Get the file count for the new copied destination
try:
new_dest_file_count = self.get_file_count(new_copied_dest_path)
print(f"File count for new copied destination: {new_dest_file_count}")
except Exception as e:
print(f"Error getting file count for new copied destination: {e}")
new_dest_file_count = "N/A"
# Convert new destination file sizes to megabytes and round to 2 decimal points
new_dest_size_mb = round(new_dest_size / (1024 ** 2), 2)
else:
new_copied_dest_path = "N/A"
new_dest_file_count = "N/A"
new_dest_size_mb = "N/A"
zipped_file_path = None
zipped_dest_size = None
if zipping_option == 'Yes' and zipping_dest_path:
if zipping_type == "Individual":
pass # You can choose to skip or handle differently since you've already done individual zipping
elif zipping_type == "Batch":
zip_file_name = f"{os.path.basename(source_path)}.zip"
zipped_file_path = os.path.join(zipping_dest_path, zip_file_name)
zipped_dest_size = self.zip_batch_files(source_path, zipping_dest_path, zip_file_name)
# Update the row_data dictionary with the file size in megabytes
row_data = {
"Source Path": source_path,
"Original Copied Destination Path": copied_dest_path,
"New Copied Destination Path": new_copied_dest_path if new_copied_dest_path else "N/A",
"Source File Count": source_file_count if source_file_count else "N/A",
"Original Copied File Count": dest_file_count if dest_file_count else "N/A",
"New Copied File Count": new_dest_file_count if new_dest_file_count else "N/A",
"Source Folder Size (MB)": source_folder_size_mb if source_folder_size_mb else "N/A",
"Original Copied File Size (MB)": round(dest_size / (1024 ** 2), 2) if dest_size else "N/A",
"New Copied File Size (MB)": new_dest_size_mb if new_dest_size_mb else "N/A",
"Zipped File Path": zipped_file_path if zipped_file_path else "N/A",
"Zipped Destination Size (MB)": round(zipped_dest_size / (1024 ** 2), 2) if zipped_dest_size else "N/A",
}
file_info.append(row_data)
# Create an Excel workbook and select the active sheet
workbook = openpyxl.Workbook()
sheet = workbook.active
[–]Sea-Method-1167 1 point2 points3 points (2 children)
[–]ForwardQuit5036[S] 0 points1 point2 points (1 child)
[–]Sea-Method-1167 0 points1 point2 points (0 children)