API
Use the FileTree class programmatically to generate directory trees from Python.
Example
from pyletree import FileTree
tree = FileTree()
print(tree)
for line in tree:
print(line)
Parameters
root_dir: str | Path = '.'Root directory pathdir_only: bool = FalseShow directories onlyfiles_only: bool = FalseShow files onlydirs_first: bool = FalseList directories before filesfiles_first: bool = FalseList files before directoriesno_pipes: bool = FalseRemove vertical pipes between branchesignore: list[str] | None = NoneGitignore-style patterns to ignorefilter: list[str] | None = NoneGitignore-style patterns to include onlyuse_gitignore: bool | str | Path | list[str | Path] = FalseRespect.gitignorerulesdepth_level: int | None = NoneLimit tree depthpath_tree: bool = FalseDisplay full paths instead of namestext_only: bool = FalsePlain text modetext_only_indent: int = 2Indentation spaces for text-only modefile_size: bool = FalseShow individual file sizesdir_size: bool = FalseShow cumulative sizes for directoriessort_size: None | 'big' | 'small' = NoneSort by sizereverse: bool = FalseReverse alphabetical sort order
Methods
get_tree() -> str
Return the tree as a formatted string.
get_dict_tree() -> dict[str, Any]
Return the tree as a nested dictionary.
get_path(pattern: str) -> list[Path]
Search for files or directories matching a pattern.
dict(tree)
FileTree supports mapping conversion via keys() and __getitem__().
Iteration
The class is iterable and yields one line of the tree at a time.
String conversion
str(tree) returns the full tree.