I believe that's because gzip never operates over directories, it acts as a compression algorithm unlike zip and tar where we could compress directories. python's implementation of gzip is to operate on files. However recursive traversal of a directory tree is easy if we look at the os.walk call.

(I haven't tested this)

def gunzip(file_path,output_path):
    with gzip.open(file_path,"rb") as f_in, open(output_path,"wb") as f_out:
        shutil.copyfileobj(f_in, f_out)

def recurse_and_gunzip(root):
    walker = os.walk(root)
    for root,dirs,files in walker:
        for f in files:
            if fnmatch.fnmatch(f,"*.gz"):
                gunzip(f,f.replace(".gz",""))
Answer from Addy on Stack Overflow
🌐
Python
docs.python.org › 3 › library › gzip.html
gzip — Support for gzip files
Source code: Lib/gzip.py This module provides a simple interface to compress and decompress files just like the GNU programs gzip and gunzip would. This is an optional module. If it is missing from...
Discussions

How to unzip gz file using Python - Stack Overflow
If you have a .tar.gz or a .tgz ... not the gzip module. 2021-02-18T17:50:25.373Z+00:00 ... Save this answer. ... Show activity on this post. ... this solution works for me on python 2.7 without importing any library, @heinst thanks a lot 2019-10-09T14:58:23.2Z+00:00 ... Just to note that this could blow up your memory as it will decompress everything ... More on stackoverflow.com
🌐 stackoverflow.com
compression - How do I compress a folder with the Python GZip module? - Stack Overflow
I'm creating Python software that compresses files/folders... How would I create a section of the code that asks for the user input of the folder location and then compresses it. I currently have the More on stackoverflow.com
🌐 stackoverflow.com
subprocess - How do I decompress a .gz file and save the decompressed file to a different directory in Python? - Stack Overflow
Because GzipFile constructs file-like object, it might be possible to run it through shutil.copyfileobj. More on stackoverflow.com
🌐 stackoverflow.com
How to unzip a massive amount of files using Windows Python 2.7?

Why over engineer? Simply gunzip -r a directory of zipped files:

gunzip -r ./directory_of_zipped_files/

EDIT: Sorry ... now noted that you said windows. This is a *nix solution.

More on reddit.com
🌐 r/learnpython
17
13
June 8, 2013
🌐
GitHub
gist.github.com › kstreepy › a9800804c21367d5a8bde692318a18f5
For a given directory, unzip all .gz files in folder, save unzipped files in folder and deleted zipped files. A python solution for instances where you do not have access to PowerShell. · GitHub
For a given directory, unzip all .gz files in folder, save unzipped files in folder and deleted zipped files. A python solution for instances where you do not have access to PowerShell. - gz_extract.py
🌐
GeeksforGeeks
geeksforgeeks.org › python › gzip-decompresss-in-python
gzip.decompress(s) in Python - GeeksforGeeks
March 26, 2020 - Syntax : gzip.decompress(string) Return : Return decompressed string.
🌐
Scaler
scaler.com › home › topics › python gzip module
Python gzip Module| Scaler Topics
December 15, 2022 - Intro: Used to decompress the data returns the bytes of the decompressed data. This Python gzip.decompress() function is capable of decompressing the multi-member gzip data (that is, multiple gzip blocks concatenated together).
🌐
Stack Abuse
stackabuse.com › bytes › how-to-unzip-a-gz-file-using-python
How to Unzip a .gz File Using Python
August 14, 2023 - Note: The tarfile module is only applicable for .tar.gz files. If you're dealing with a simple .gz file, you should use the gzip module or the sh module with the gunzip command. In this Byte, we have seen how to unzip .gz files in Python using the sh module, the gzip module, and the tarfile module.
Find elsewhere
🌐
Medium
medium.com › @anirudhbishnoi5 › gzip-module-in-python-230aafd7d17a
gzip module in Python. gzip is an inbuilt module in python… | by Anirudh Bishnoi | Medium
April 9, 2023 - the gzip class would automatically read and write the gzip format files and automatically compresses and decompresses the files into file object. syntax : gzip.open(filename, mode=’<mode-argument>’, compresslevel=<compression-level int value>,encoding=None) It is used to read or write into the files of gzip file object.
🌐
The Python Code
thepythoncode.com › article › compress-decompress-files-tarfile-python
How to Compress and Decompress Files in Python - The Python Code
Related: How to Encrypt and Decrypt Files in Python. Let's get started; we will be using the tarfile built-in module, so we don't have to install anything; you can optionally install tqdm just for printing progress bars: ... Let's start with compression. The following function is responsible for compressing a file/folder or a list of files/folders: def compress(tar_file, members): """ Adds files (`members`) to a tar_file and compress it """ # open file for gzip compressed writing tar = tarfile.open(tar_file, mode="w:gz") # with progress bar # set the progress bar progress = tqdm(members) for member in progress: # add file/folder/link to the tar file (compress) tar.add(member) # set the progress description of the progress bar progress.set_description(f"Compressing {member}") # close the file tar.close()
🌐
Python Forum
python-forum.io › thread-38556.html
python gzip all files from a folder
Hi Team, I want to gzip all files of a folder \or complete folder. save with different name. before deleting all files from a folder. how to achieve this. with the below code I can gzip single file. import gzip import shutil fname = 'D:\bigcsv.cs...
🌐
Xah Lee
xahlee.info › python › gzip.html
Python: Compress Decompress Gzip File
March 23, 2019 - # compress a gzip file import gzip input = open("/Users/joe/xxtest", 'rb') s = input.read() input.close() output = gzip.GzipFile("/Users/joe/xxtest.gz", 'wb') output.write(s) output.close() print("done") # decompress a gzip file import gzip input = gzip.GzipFile("/Users/joe/xxtest.gz", 'rb') s = input.read() input.close() output = open("/Users/joe/xxtest", 'wb') output.write(s) output.close() print("done")
🌐
GitHub
gist.github.com › jiankaiwang › f5056a34bbbf595c9553efb36aff64ec
Compress and decompress a gzip file in python. · GitHub
Compress and decompress a gzip file in python. GitHub Gist: instantly share code, notes, and snippets.
🌐
CodersLegacy
coderslegacy.com › home › python › python gzip module – compress and decompress files
Python gzip module - compress and decompress files - CodersLegacy
January 30, 2022 - The first thing you can do is open up a file with compressed data, and then use the gzip.read() function on it. This will return the decompressed data exactly like it was before.
🌐
Aspose
blog.aspose.com › aspose.blogs › create and unzip gzip files in python
GZIP Files in Python | Python GZIP Module
September 11, 2023 - Aspose.ZIP for Python simplifies the process of working with GZIP files by providing a robust and feature-rich library for compression and decompression tasks. In this tutorial, we covered the basics of creating a GZIP file in Python. In addition, we have shown how to unzip GZIP files and extract their content to the directory.
🌐
GitHub
github.com › mxmlnkn › rapidgzip
GitHub - mxmlnkn/rapidgzip: Gzip Decompression and Random Access for Modern Multi-Core Machines · GitHub
git clone --recursive https://github.com/mxmlnkn/rapidgzip.git cd rapidgzip/python/rapidgzip/ rm -rf dist python3 -m build python3 -m pip install --force-reinstall --user --break-system-packages dist/rapidgzip-*.whl · Following are benchmarks showing the decompression bandwidth over the number of used cores. There are two rapidgzip variants shown: (index) and (no index). Rapidgzip is generally faster when given an index with --import-index because it can delegate the decompression to ISA-l or zlib while it has to use its own custom-written gzip decompression engine when no index exists yet.
Starred by 457 users
Forked by 16 users
Languages   Python
🌐
AskPython
askpython.com › python-modules › gzip-module-in-python
Python HowTo - Using the gzip Module in Python - AskPython
August 6, 2022 - Let’s now try to decompress it and read it’s contents. Now, similar to the write() function via the wrapper, we can also read() using that same function. import gzip import os import io name = 'sample.txt.gz' with gzip.open(name, 'rb') as ip: with io.TextIOWrapper(ip, encoding='utf-8') as decoder: # Let's read the content using read() content = decoder.read() print(content)
🌐
Bobby Hadz
bobbyhadz.com › blog › how-to-unzip-gz-file-in-python
How to unzip a .gz file using Python [5 simple Ways] | bobbyhadz
The compression keyword argument can be set to gzip for on-the-fly decompression of on-disk data. You can also use the sh module to unzip a .gz file in Python.