Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Unzip
- import os, zipfile
- dir_name = 'C:\test'
- extension = ".gz"
- dir2='C:\testextract'
- os.chdir(dir_name) # change directory from working dir to dir with files
- for item in os.listdir(dir_name): # loop through items in dir
- if item.endswith(extension): # check for ".zip" extension
- file_name = os.path.abspath(item) # get full path of files
- zip_ref = zipfile.ZipFile(file_name) # create zipfile object
- zip_ref.extractall(dir2) # extract file to dir
- zip_ref.close() # close file
- os.remove(file_name) # delete zipped file
Add Comment
Please, Sign In to add comment