Skip to content

Instantly share code, notes, and snippets.

@thepushkarp
Created July 13, 2022 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepushkarp/94f810082da84578a1cd4b65d9a485e4 to your computer and use it in GitHub Desktop.
Save thepushkarp/94f810082da84578a1cd4b65d9a485e4 to your computer and use it in GitHub Desktop.
Extract gzipped files
import gzip
import os
root_folder = "mock-data"
for root, dirs, files in os.walk(root_folder):
# if file is a .csv.gzip, extract it
for file in files:
if file.endswith(".gz"):
file_path = os.path.join(root, file)
with gzip.open(file_path, "rb") as f_in:
with open(file_path[:-3], "wb") as f_out:
f_out.write(f_in.read())
os.remove(file_path)
print(f"Extracted {file_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment