Last active
May 9, 2020 20:09
Star
You must be signed in to star a gist
Tar File Explororo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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