-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_it.py
More file actions
25 lines (20 loc) · 745 Bytes
/
zip_it.py
File metadata and controls
25 lines (20 loc) · 745 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
from pathlib import Path
from datetime import datetime
import zipfile
root_dir = Path('files/projectA')
# get timestamp for archive name
now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
archive_name = now + '_archive.zip'
archive_path = root_dir / Path(archive_name)
# write all markdown pages in dir to zip container
with zipfile.ZipFile(archive_path, 'w') as zf:
for path in root_dir.glob('*.md'):
zf.write(path)
# delete source files
# path.unlink()
# unzip all containers in root dir recursively
destination_path = Path('files/unzipped')
for path in root_dir.rglob('*.zip'):
with zipfile.ZipFile(path, 'r') as zf:
sub_dir = destination_path / Path(path.stem)
zf.extractall(path=sub_dir)