-
-
Save rayou/5310692 to your computer and use it in GitHub Desktop.
Python: unzip.py
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 zipfile | |
| import os | |
| #Extracts files on a zip file into a given directory, if no directory is given, | |
| #it extracts the files into the zip file directory. | |
| def unzip_file(zip_file, my_path=None): | |
| zip_file = zipfile.ZipFile(zip_file) #open the zip file | |
| if my_path != None: #if directory is given, and doesn't exist, create directory. | |
| if not os.path.isdir(my_path): | |
| os.makedirs(my_path) | |
| for f in zip_file.namelist(): #extract all the files into the given directory | |
| zip_file.extract(f, my_path=None) | |
| else: #if no directory is given, extract the files into the zipfiles's directory. | |
| for f in zip_file.namelist(): | |
| zip_file.extract(f) | |
| zip_file = 'C:\Users\carlos\Desktop\python\Json_File.zip' #set the zipfile's directory. | |
| #my_path = 'C:\Users\carlos\Desktop\python\Json_File' #set the directory to extract files. | |
| unzip_file(zip_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment