{"record":{"id":"3d542a9300129ab1","repo":"lllyasviel/Fooocus","slug":"folder-path-is-not-a-valid-directory","errorCode":null,"errorMessage":"Folder path is not a valid directory.","messagePattern":"Folder path is not a valid directory\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"modules/extra_utils.py","lineNumber":14,"sourceCode":"import os\nfrom ast import literal_eval\n\n\ndef makedirs_with_log(path):\n    try:\n        os.makedirs(path, exist_ok=True)\n    except OSError as error:\n        print(f'Directory {path} could not be created, reason: {error}')\n\n\ndef get_files_from_folder(folder_path, extensions=None, name_filter=None):\n    if not os.path.isdir(folder_path):\n        raise ValueError(\"Folder path is not a valid directory.\")\n\n    filenames = []\n\n    for root, _, files in os.walk(folder_path, topdown=False):\n        relative_path = os.path.relpath(root, folder_path)\n        if relative_path == \".\":\n            relative_path = \"\"\n        for filename in sorted(files, key=lambda s: s.casefold()):\n            _, file_extension = os.path.splitext(filename)\n            if (extensions is None or file_extension.lower() in extensions) and (name_filter is None or name_filter in _):\n                path = os.path.join(relative_path, filename)\n                filenames.append(path)\n\n    return filenames\n\n\ndef try_eval_env_var(value: str, expected_type=None):\n    try:","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/extra_utils.py#L1-L32","documentation":"get_files_from_folder in modules/extra_utils.py walks a folder collecting files filtered by extension and name substring; it first requires that folder_path is an existing directory (os.path.isdir) and raises ValueError('Folder path is not a valid directory.') otherwise. Note this rejects both nonexistent paths and existing files, and it does not auto-create the folder.","triggerScenarios":"Calling get_files_from_folder('/path/that/does/not/exist') or passing a file path instead of a directory; also a directory that exists but is not readable can behave oddly on some platforms.","commonSituations":"Wildcard/loose-file features and folder-scanning UI fields where the user typos the path, points at a .txt/.csv file, or the folder has not been created yet (makedirs_with_log exists in the same file but is not applied here).","solutions":["Verify the path exists and is a directory before calling: os.path.isdir(folder_path).","If the folder may be missing, create it first with makedirs_with_log(folder_path) from the same module.","Pass the directory (e.g. models/loras), not a filename, when scanning for model files."],"exampleFix":"# before\nfiles = get_files_from_folder('models/loras/my_lora.safetensors')\n# after\nfiles = get_files_from_folder('models/loras')","handlingStrategy":"validation","validationCode":"import os\nif not os.path.isdir(folder_path):\n    raise ValueError(f'{folder_path!r} is not a directory')  # or: makedirs_with_log(folder_path) then proceed","typeGuard":"def is_scannable_dir(p: str) -> bool:\n    return os.path.isdir(p)  # True only for existing directories, not files","tryCatchPattern":null,"preventionTips":["Create expected folders at startup with makedirs_with_log instead of assuming they exist.","Distinguish files from directories before scanning: pass folder roots, not model file paths."],"tags":["filesystem","validation","directory-scan","user-input"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}