继续Unzip zip files in folders and subfolders with python此代码与python 3一起工作:
#!/usr/bin/env python3
import logging
from pathlib import Path
from shutil import unpack_archive
zip_files = Path(r"C:\Project\layers").rglob("*.zip")
while True:
try:
path = next(zip_files)
except StopIteration:
break # no more files
except PermissionError:
logging.exception("permission error")
else:
extract_dir = path.with_name(path.stem)
unpack_archive(str(path), str(extract_dir), 'zip')
我使用python 2.7.8并且无法更改python的版本,因为它会影响其他重要的程序。当我运行代码时,我收到一个错误:
ImportError: No module named pathlib
如何更改代码以使其有效?