wijjit.helpers.load_filesystem_tree

wijjit.helpers.load_filesystem_tree(root_path, max_depth=None, show_hidden=False, include_files=True, include_metadata=True, exclude=None, filter_func=None)[source]

Load a filesystem directory structure as a tree.

Recursively scans a directory and returns a nested dictionary structure suitable for use with the Tree display element.

Parameters:
  • root_path (str or Path) – Root directory to scan

  • max_depth (int, optional) – Maximum depth to traverse (None for unlimited)

  • show_hidden (bool) – Include hidden files and directories (default: False)

  • include_files (bool) – Include files in the tree (default: True)

  • include_metadata (bool) – Include the human-readable file size (default: True)

  • exclude (list of str, optional) – List of glob patterns to exclude (e.g., ["*.pyc", "__pycache__"])

  • filter_func (callable, optional) – Custom filter function that takes a Path and returns True to include

Returns:

Tree structure with keys: - label: Display name - value: Full path as string - type: “folder” or “file” - children: List of child nodes (for folders) - size: Human-readable size (if include_metadata=True and is file)

Return type:

dict

Examples

Basic usage:

from wijjit.helpers import load_filesystem_tree

tree_data = load_filesystem_tree("/path/to/dir")

With options:

tree_data = load_filesystem_tree(
    "/path/to/dir",
    max_depth=3,
    show_hidden=False,
    exclude=["*.pyc", "*.pyo", "__pycache__", ".git"]
)

Use with Tree element:

app = Wijjit(initial_state={
    "file_tree": load_filesystem_tree("./src"),
    "expanded_nodes": [],
})