-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunzipper.py
43 lines (34 loc) · 1.01 KB
/
unzipper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#author: dns43
#this script walks threw a specified directory
#and extracts all .zip files to their parent directory
import zipfile
import os
folderlist = []
filelist = []
path = "C:\\Users\\dns43\\Desktop\\Drexel\\webscraper\\data"
#dns43: recursively walks through folders and creates a list of .zip files
#dns43: expects all files to be zipfiles! does not handle exceptions!
def collectZipFiles(pfad):
for entry in os.scandir(pfad):
print(entry.path)
if entry.is_dir():
folderlist.append(entry.path)
collectZipFiles(entry.path)
elif entry.is_file():
filelist.append(entry.path)
collectZipFiles(path)
#dns43: some verbose debug information
print('Folders:')
print(len(folderlist))
print('Files:')
print(len(filelist))
#dns43: extracts all files in the list to their current directory
#dns43: expects all files to be zipfiles! does not handle exceptions!
i=0
for file in filelist:
print(file)
print(file[:-3])
zip_ref = zipfile.ZipFile(file, 'r')
zip_ref.extractall(file[:-3])
zip_ref.close()
i=i+1