Skip to content

Utils

is_archive

is_archive(file: StrPath) -> bool

Check whether the given archive file is a supported archive or not.

Parameters:

Name Type Description Default
file StrPath

Path to the archive file.

required

Returns:

Type Description
bool

True if the archive is supported, False otherwise.

Source code in src/archivefile/_utils.py
def is_archive(file: StrPath) -> bool:
    """
    Check whether the given archive file is a supported archive or not.

    Parameters
    ---------
    file : StrPath
        Path to the archive file.

    Returns
    -------
    bool
        True if the archive is supported, False otherwise.
    """
    file = realpath(file)

    if file.exists():
        return is_tarfile(file) or is_zipfile(file) or is_rarfile(file) or is_rarfile_sfx(file) or is_7zfile(file)
    else:
        return False