Closed geroldmeisinger closed 1 month ago
sort the file list before processing
LLM:
You can use the pathlib module in Python to recursively get all file paths in a directory and sort them. Here's a complete example:
from pathlib import Path def get_all_file_paths_sorted(directory): # Get all file paths recursively file_paths = [p for p in Path(directory).rglob('*') if p.is_file()] # Sort the file paths file_paths_sorted = sorted(file_paths, key=lambda p: str(p)) return file_paths_sorted
Python's set type does not maintain order, but you can sort the items before storing them in a set. However, once the items are in the set, they will not be ordered. To maintain a sorted set-like behavior, you can use sortedcontainers.SortedSet from the sortedcontainers library, which maintains sorted order.
file_paths = SortedSet(str(p) for p in Path(directory).rglob('*') if p.is_file())
sort the file list before processing
Maybe I'll consider this when I deal with #181.
with this file:![000029685](https://github.com/jhc13/taggui/assets/112266044/45415b09-460f-4114-9e4f-c4f12c49a26c)
a simple catch-all should fix it:
the app crashes. when i restart it tries to load the same directory again and crashes. afterwards it works again but all settings are deleted.
(btw I think you should sort the file list before processing, makes it a little more predictable.)