Guest User

Untitled

a guest
Mar 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #Unzip
  2. import os, zipfile
  3.  
  4. dir_name = 'C:\test'
  5. extension = ".gz"
  6. dir2='C:\testextract'
  7.  
  8. os.chdir(dir_name) # change directory from working dir to dir with files
  9.  
  10. for item in os.listdir(dir_name): # loop through items in dir
  11. if item.endswith(extension): # check for ".zip" extension
  12. file_name = os.path.abspath(item) # get full path of files
  13. zip_ref = zipfile.ZipFile(file_name) # create zipfile object
  14. zip_ref.extractall(dir2) # extract file to dir
  15. zip_ref.close() # close file
  16. os.remove(file_name) # delete zipped file
Add Comment
Please, Sign In to add comment