1import zipfile
2with zipfile.ZipFile("file.zip","r") as zip_ref:
3 zip_ref.extractall("targetdir")
1import zipfile
2with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
3 zip_ref.extractall(directory_to_extract_to)
1url = 'https://codeload.github.com/fogleman/Minecraft/zip/master'
2
3# downloading with requests
4
5# import the requests library
6import requests
7
8
9# download the file contents in binary format
10r = requests.get(url)
11
12# open method to open a file on your system and write the contents
13with open("minemaster1.zip", "wb") as code:
14 code.write(r.content)
15
16
17# downloading with urllib
18
19# import the urllib library
20import urllib
21
22# Copy a network object to a local file
23urllib.urlretrieve(url, "minemaster.zip")
24
1import os
2import optparse
3import zipfile
4
5def get_arguments():
6 parser = optparse.OptionParser()
7 parser.add_option("--src","--source",dest="paths", help="Removing file with extension .SRT and .VTT")
8 (options,arguments)=parser.parse_args()
9 if not options.paths:
10 parser.error("[-] Please specify source, use --help for more info.")
11 return options
12
13
14def Source_folder(folder_path):
15 print('[+] Extracting zip file')
16 for path, dir_list, file_list in os.walk(folder_path):
17 try:
18 for file_name in file_list:
19 if file_name.endswith(".zip"):
20 abs_file_path = os.path.join(path, file_name)
21 parent_path = os.path.split(abs_file_path)[0]
22 output_folder_name = os.path.splitext(abs_file_path)[0]
23 output_path = os.path.join(parent_path, output_folder_name)
24
25 zip_obj = zipfile.ZipFile(abs_file_path, 'r')
26 zip_obj.extractall(output_path)
27 zip_obj.close()
28
29 except FileNotFoundError:
30 print('Error', file_name)
31
32
33options = get_arguments()
34Source_folder(options.paths)