Skip to content

Instantly share code, notes, and snippets.

@dustinbutterworth
Created August 22, 2022 17:03
Show Gist options
  • Save dustinbutterworth/9db2e3fa99337cdba1c838054ba5b8ba to your computer and use it in GitHub Desktop.
Save dustinbutterworth/9db2e3fa99337cdba1c838054ba5b8ba to your computer and use it in GitHub Desktop.
Untar, Gunzip all files in a directory into their own directory
import os
import tarfile
base_dir = '/path/to/tarfiles'
import os
for path, directories, files in os.walk(base_dir):
for f in files:
if f.endswith(".tar.gz"):
filepath = f.replace(".tar.gz", "")
tar = tarfile.open(os.path.join(path,f), 'r:gz')
tar.extractall(path=filepath)
tar.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment