Python Forum
Moving specific files then unzipping/decompressing - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Moving specific files then unzipping/decompressing (/thread-33410.html)



Moving specific files then unzipping/decompressing - christophereccles - Apr-23-2021

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


RE: Moving specific files then unzipping/decompressing - Larz60+ - Apr-24-2021

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).



RE: Moving specific files then unzipping/decompressing - ndc85430 - Apr-24-2021

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.