Created
July 13, 2022 10:10
-
-
Save thepushkarp/94f810082da84578a1cd4b65d9a485e4 to your computer and use it in GitHub Desktop.
Extract gzipped files
This file contains hidden or 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 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