Skip to content
New: Star-import, signal unraveling, Python 3.12 support, and more

# path_ module

Utilities for working with paths.

## check_mkdir function

    check_mkdir(
        dir_path,
        mkdir=None,
        mode=None,
        parents=None,
        exist_ok=None
    )

Check whether the path to a directory exists and create if it doesn't.

For defaults, see `mkdir` in path.

## dir_exists function

    dir_exists(
        dir_path
    )

Check whether a directory exists.

## dir_size function

    dir_size(
        dir_path,
        readable=True,
        **kwargs
    )

Get size of a directory.

## dir_tree function

    dir_tree(
        dir_path,
        level=-1,
        limit_to_directories=False,
        length_limit=1000,
        sort=True,
        space='    ',
        branch='│   ',
        tee='├── ',
        last='└── '
    )

Given a directory Path object print a visual tree structure.

Inspired by this answer: https://stackoverflow.com/a/59109706

## file_exists function

    file_exists(
        file_path
    )

Check whether a file exists.

## file_size function

    file_size(
        file_path,
        readable=True,
        **kwargs
    )

Get size of a file.

## list_any_files function

    list_any_files(
        path=None,
        recursive=False
    )

List files and directories matching a path.

If the directory path is not provided, the current working directory is used.

## list_dirs function

    list_dirs(
        path=None,
        recursive=False
    )

List directories matching a path using list_any_files().

## list_files function

    list_files(
        path=None,
        recursive=False
    )

List files matching a path using list_any_files().

## make_dir function

    make_dir(
        dir_path,
        **kwargs
    )

Make an empty directory.

## make_file function

    make_file(
        file_path,
        mode=438,
        exist_ok=True,
        **kwargs
    )

Make an empty file.

## print_dir_tree function

    print_dir_tree(
        *args,
        **kwargs
    )

Generate a directory tree with `tree` and print it out.

## remove_dir function

    remove_dir(
        dir_path,
        missing_ok=False,
        with_contents=False
    )

Remove (delete) a directory.

## remove_file function

    remove_file(
        file_path,
        missing_ok=False
    )

Remove (delete) a file.

#### Cookie consent

We use cookies to recognize your repeated visits and preferences, as well as to measure the effectiveness of our documentation and whether users find what they're searching for. With your consent, you're helping us to make our documentation better.

- Google Analytics
- GitHub

Manage settings