lllyasviel/Fooocus · error · ValueError

Folder path is not a valid directory.

Error message

Folder path is not a valid directory.

What it means

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.

Source

Thrown at modules/extra_utils.py:14

import os
from ast import literal_eval


def makedirs_with_log(path):
    try:
        os.makedirs(path, exist_ok=True)
    except OSError as error:
        print(f'Directory {path} could not be created, reason: {error}')


def get_files_from_folder(folder_path, extensions=None, name_filter=None):
    if not os.path.isdir(folder_path):
        raise ValueError("Folder path is not a valid directory.")

    filenames = []

    for root, _, files in os.walk(folder_path, topdown=False):
        relative_path = os.path.relpath(root, folder_path)
        if relative_path == ".":
            relative_path = ""
        for filename in sorted(files, key=lambda s: s.casefold()):
            _, file_extension = os.path.splitext(filename)
            if (extensions is None or file_extension.lower() in extensions) and (name_filter is None or name_filter in _):
                path = os.path.join(relative_path, filename)
                filenames.append(path)

    return filenames


def try_eval_env_var(value: str, expected_type=None):
    try:

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Verify the path exists and is a directory before calling: os.path.isdir(folder_path).
  2. If the folder may be missing, create it first with makedirs_with_log(folder_path) from the same module.
  3. Pass the directory (e.g. models/loras), not a filename, when scanning for model files.

Example fix

# before
files = get_files_from_folder('models/loras/my_lora.safetensors')
# after
files = get_files_from_folder('models/loras')
Defensive patterns

Strategy: validation

Validate before calling

import os
if not os.path.isdir(folder_path):
    raise ValueError(f'{folder_path!r} is not a directory')  # or: makedirs_with_log(folder_path) then proceed

Type guard

def is_scannable_dir(p: str) -> bool:
    return os.path.isdir(p)  # True only for existing directories, not files

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/3d542a9300129ab1. Report an issue: GitHub.