Skip to content

Instantly share code, notes, and snippets.

@jaganadhg
Last active May 9, 2020 20:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jaganadhg/7ea96a00683a09cd48e5ecb5f8bb396a to your computer and use it in GitHub Desktop.
Tar File Explororo
import tarfile
def get_file_match_patterns(tar_file_path : str, pattern : str) -> int:
"""
Count number of file containing pattern in a tar file without extract.
:params tar_file_path: Absolute path to tar file
:params pattern: patterns to searh in the file names
:returns count_matching: Count of matching files
"""
tar_content = tarfile.open(tar_file_path)
names_of_files = [files.name for files in tar_content.getmembers()]
tar_content.close()
matching_files = list(filter(lambda x: pattern in x, names_of_files))
count_matching = len(matching_files)
return count_matching
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment