diff options
author | CookieHCl <nhc7502@snu.ac.kr> | 2022-10-16 11:50:24 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2022-10-16 13:36:06 +0000 |
commit | 91235d8008372862b1f232f7bf99da310a5955e4 (patch) | |
tree | 8109bfe33afa126aca6ef610b52bccaad5704d46 /modules/images_history.py | |
parent | 36a0ba357ab0742c3c4a28437b68fb29a235afbe (diff) | |
download | stable-diffusion-webui-gfx803-91235d8008372862b1f232f7bf99da310a5955e4.tar.gz stable-diffusion-webui-gfx803-91235d8008372862b1f232f7bf99da310a5955e4.tar.bz2 stable-diffusion-webui-gfx803-91235d8008372862b1f232f7bf99da310a5955e4.zip |
Fix FileNotFoundError in history tab
Now only traverse images when directory exists
Diffstat (limited to 'modules/images_history.py')
-rw-r--r-- | modules/images_history.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/modules/images_history.py b/modules/images_history.py index 9260df8a..e6284142 100644 --- a/modules/images_history.py +++ b/modules/images_history.py @@ -1,6 +1,6 @@ import os import shutil - +import sys def traverse_all_files(output_dir, image_list, curr_dir=None): curr_path = output_dir if curr_dir is None else os.path.join(output_dir, curr_dir) @@ -24,10 +24,14 @@ def traverse_all_files(output_dir, image_list, curr_dir=None): def get_recent_images(dir_name, page_index, step, image_index, tabname): page_index = int(page_index) - f_list = os.listdir(dir_name) image_list = [] - image_list = traverse_all_files(dir_name, image_list) - image_list = sorted(image_list, key=lambda file: -os.path.getctime(os.path.join(dir_name, file))) + if not os.path.exists(dir_name): + pass + elif os.path.isdir(dir_name): + image_list = traverse_all_files(dir_name, image_list) + image_list = sorted(image_list, key=lambda file: -os.path.getctime(os.path.join(dir_name, file))) + else: + print(f"ERROR: {dir_name} is not a directory. Check the path in the settings.", file=sys.stderr) num = 48 if tabname != "extras" else 12 max_page_index = len(image_list) // num + 1 page_index = max_page_index if page_index == -1 else page_index + step |