Created
June 11, 2019 16:09
-
-
Save kstreepy/a9800804c21367d5a8bde692318a18f5 to your computer and use it in GitHub Desktop.
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.
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 os, gzip, shutil | |
dir_name = 'x' | |
def gz_extract(directory): | |
extension = ".gz" | |
os.chdir(directory) | |
for item in os.listdir(directory): # loop through items in dir | |
if item.endswith(extension): # check for ".gz" extension | |
gz_name = os.path.abspath(item) # get full path of files | |
file_name = (os.path.basename(gz_name)).rsplit('.',1)[0] #get file name for file within | |
with gzip.open(gz_name,"rb") as f_in, open(file_name,"wb") as f_out: | |
shutil.copyfileobj(f_in, f_out) | |
os.remove(gz_name) # delete zipped file | |
gz_extract(dir_name) |
Thank you for writing this!
Thanks for letting me know it was helpful. It really made my day that someone found it useful
Useful for me too, thank you!
Thanks very useful!
Thanks, very useful.
Whne using this as a subroutine, changing the working directory could be annoying since it could mess with the function calling it.
very useful. thank you.
This really helped, thank you.
Thanks for the code
very useful. thank you.
Thanks a lot, saves me a lot of effort
Extremely useful, thanks
My thanks!!!
Thank you for posting this! It was useful to me. You've made the world a slightly better place :)
Very useful, thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for writing this!