Python Forum

Full Version: Moving specific files then unzipping/decompressing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have a folder with a number of subfolders inside. Inside these folders are a couple of .gz files. I need to recursively copy these files to there own folder and then unzip them.the new folder needs to be in the same location as the original file. I have been on this for days, I would post some code, but it would be meaningless as I have no idea which code that I've used came closest to the correct method. Any help greatly appreciated. Id prefer to get it done using only python and only standard libraries, but I'm not limited to that.
Thankyou in advance for any help given
This is Pretty straight forward:
see: https://docs.python.org/3/library/zipfile.html

Example:
fzip = zipfile.ZipFile('myzip.zip')
# To extract all:
fzip.extractall() # or fzip.extractall("destination_directory_name_here")
# (be cautious of this command, if you don't trust zip source).
If what you have are gzip files, as the .gz extension usually indicates, there's a standard library module for those too: https://docs.python.org/3/library/gzip.html.