Skip to content

Commit

Permalink
image extension prioritization added yurijmikhalevich#15
Browse files Browse the repository at this point in the history
  • Loading branch information
abidkhan484 committed Oct 2, 2024
1 parent 5f7a807 commit 097f9df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rclip/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Callable, Pattern

COUNT_FILES_UPDATE_EVERY = 10_000
PRIORITIZED_IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png'}


def count_files(
Expand Down Expand Up @@ -30,9 +31,16 @@ def walk(
while dirs_to_process:
dir = dirs_to_process.pop()
with os.scandir(dir) as it:
for entry in it:
base_names = {}
sorted_entries = sorted(it, key=(
lambda entry: os.path.splitext(entry.name)[1].lower() not in PRIORITIZED_IMAGE_EXTENSIONS
))
for entry in sorted_entries:
if entry.is_dir():
if not exclude_dir_re.match(entry.path):
dirs_to_process.append(entry.path)
elif entry.is_file() and file_re.match(entry.name):
yield entry
base_name = os.path.splitext(entry.name)[0]
if base_name not in base_names:
base_names[base_name] = entry.name
yield entry

0 comments on commit 097f9df

Please sign in to comment.