Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cachyos/Scripts/WIP/gphotos/Splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def group_photos(photos_folder, target_folder_size):
photos_folder, f"Group_{current_group_num}"
)

abs_group_folder = os.path.abspath(current_group_folder)

for root, dirs, files in os.walk(photos_folder):
# Exclude generated group folders from os.walk
dirs[:] = [d for d in dirs if not d.startswith("Group_")]
Expand Down Expand Up @@ -90,10 +92,11 @@ def group_photos(photos_folder, target_folder_size):
create_new_folder(photos_folder, f"Group_{current_group_num}")
current_group_size = 0

abs_group_folder = os.path.abspath(current_group_folder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line is executed on every iteration of the while loop. However, the resulting abs_group_folder is only used after the loop terminates. To further optimize, this calculation should be performed only once after the while loop completes. This would prevent redundant os.path.abspath() calls if the loop needs to iterate multiple times to find a suitable group folder.


# Move the file to the current group folder if it's not already there
# We use absolute paths for comparison to be safe
abs_file_path = os.path.abspath(file_path)
abs_group_folder = os.path.abspath(current_group_folder)

if os.path.commonpath([abs_file_path, abs_group_folder]) != abs_group_folder:
try:
Expand Down
Loading