Skip to content

file (3)

dir

dir(s)

Return true if the pathname refers to an existing directory.

Example

Jinja call:

{% if "src" is dir %}
True!
{% endif %}
Result:
True!

DocStrings
Source code in python3.12/genericpath.py
39
40
41
42
43
44
45
def isdir(s):
    """Return true if the pathname refers to an existing directory."""
    try:
        st = os.stat(s)
    except (OSError, ValueError):
        return False
    return stat.S_ISDIR(st.st_mode)

file

file(path)

Test whether a path is a regular file

Example

Jinja call:

{% if "README.md" is file %}
True!
{% endif %}
Result:
True!

DocStrings
Source code in python3.12/genericpath.py
27
28
29
30
31
32
33
def isfile(path):
    """Test whether a path is a regular file"""
    try:
        st = os.stat(path)
    except (OSError, ValueError):
        return False
    return stat.S_ISREG(st.st_mode)

folder_with_files

folder_with_files(directory: str | os.PathLike[str]) -> bool

Check if given directory exists and contains any files.

Example

Jinja call:

{% if "./src" is folder_with_files %}
True!
{% endif %}
Result:
True!

DocStrings

Parameters:

Name Type Description Default
directory str | PathLike[str]

The directoy to check

required
Source code in src/jinjarope/envtests.py
168
169
170
171
172
173
174
175
176
177
def contains_files(directory: str | os.PathLike[str]) -> bool:
    """Check if given directory exists and contains any files.

    Supports regular file paths and fsspec URLs.

    Args:
        directory: The directoy to check
    """
    path = upath.UPath(directory)
    return path.exists() and any(path.iterdir())