get_archived_path

get_archived_path#

get_archived_path(archive_path: str | CloudPath | Path, regex: str, as_list: bool = False, case_sensitive: bool = False, file_list: list | None = None, **kwargs) list | CloudPath | Path[source]#

Get archived file path from inside the archive.

Warning

If as_list is False, it will only return the first file matched !

You can use this site to build your regex.

Parameters:
  • archive_path (AnyPathStrType) – Archive path

  • regex (str) – File regex (used by re) as it can be found in the getmembers() list

  • as_list (bool) – If true, returns a list (including all found files). If false, returns only the first match

  • case_sensitive (bool) – If true, the regex is case-sensitive.

  • file_list (list) – List of files to get archived from. Optional, if not given it will be re-computed.

Returns:

Path from inside the zipfile

Return type:

Union[list, str]

Example

>>> arch_path = 'D:/path/to/zip.zip'
>>> file_regex = '.*dir.*file_name'  # Use .* for any character
>>> path = get_archived_path(arch_path, file_regex)
'dir/filename.tif'