diff options
| author | suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> | 2023-04-05 19:49:39 +0200 |
|---|---|---|
| committer | suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> | 2023-04-05 19:49:39 +0200 |
| commit | 82397cc5d10accf703e3ce6349a18adbc507cb75 (patch) | |
| tree | 0e02717dec94ef75b9c963879024e236e0b8a74c | |
| parent | 75b43746a022c4f0c18b4d9e6cae6b7519e1426b (diff) | |
| download | decky-loader-optimise-filepickerls-util.tar.gz decky-loader-optimise-filepickerls-util.zip | |
Implement feedback for filepicker optimalisationsoptimise-filepickerls-util
| -rw-r--r-- | backend/utilities.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/backend/utilities.py b/backend/utilities.py index fba2dcbc..6109755a 100644 --- a/backend/utilities.py +++ b/backend/utilities.py @@ -188,23 +188,23 @@ class Utilities: # return 0 # file_names = sorted(os.listdir(path), key=sorter, reverse=True) # TODO provide more sort options - items = list(os.scandir(path)) - files = sorted([x for x in items if x.is_file()], key=lambda x: x.name) - folders = sorted([x for x in items if x.is_dir()], key=lambda x: x.name) + realpath = os.path.realpath(path) + files, folders = [], [] - def to_dict(entry : os.DirEntry[str], is_dir : bool): - return { - "isdir": is_dir, - "name": entry.name, - "realpath": os.path.realpath(entry.path) - } - - all = [to_dict(x, True) for x in folders] + ([to_dict(x, False) for x in files] if include_files else []) + for x in os.scandir(realpath): + if x.is_dir(): + folders.append(x) + elif include_files: + files.append(x) + + files = sorted(files, key=lambda x: x.name) + folders = sorted(folders, key=lambda x: x.name) + all = [{ "isdir": x.is_dir(), "name": x.name, "realpath": x.path } for x in folders + files] return { - "realpath": os.path.realpath(path), + "realpath": realpath, "files": all[(page-1)*max:(page)*max], - "total": len(items) + "total": len(all) } # Based on https://stackoverflow.com/a/46422554/13174603 |
