-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_dir.py
More file actions
37 lines (30 loc) · 750 Bytes
/
zip_dir.py
File metadata and controls
37 lines (30 loc) · 750 Bytes
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
import os
import zipfile
# Not relevant to judges
IGNORE = set([
'.git',
'__pycache__',
'in',
'out',
'.gitignore',
'LICENSE',
'Makefile',
'README.md',
'hashcode21.zip',
'zip_dir.py',
])
def zip_directory(zf):
for root, dirs, files in os.walk('./'):
dirs[:] = [d for d in dirs if d not in IGNORE]
for file in files:
if file in IGNORE:
continue
zf.write(
os.path.join(root, file),
os.path.relpath(os.path.join(root, file),
os.path.join('./', '..'))
)
if __name__ == '__main__':
zf = zipfile.ZipFile('hashcode21.zip', 'w', zipfile.ZIP_DEFLATED)
zip_directory(zf)
zf.close()