Created
December 20, 2017 16:02
-
-
Save ripiuk/556a35f46c5889781c5619f632c4501b to your computer and use it in GitHub Desktop.
Extract all tars in the directory
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 os | |
import tarfile | |
PATH_TO_DIR_WITH_TARS = '/home/username/sub_folder/' | |
files = [file for file in os.listdir(PATH_TO_DIR_WITH_TARS) if | |
os.path.isfile(os.path.join(PATH_TO_DIR_WITH_TARS, file))] | |
for file in files: | |
file_name, file_extension = os.path.splitext(file) | |
if file_extension == '.tar': | |
with tarfile.open(os.path.join(PATH_TO_DIR_WITH_TARS, file)) as tar: | |
tar.extractall(path=PATH_TO_DIR_WITH_TARS) # extract files to the same directory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment