2

Continusly to Unzip zip files in folders and subfolders with python this code work with 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')

i work with python 2.7.8 and can't change the version of python because it affect other important programs. When i run the code i get an error:

ImportError: No module named pathlib

How can i change the code so it will work?

Community
  • 1
  • 1
newGIS
  • 598
  • 3
  • 10
  • 26
  • there is `pathlib` version that works on Python 2.7. [As I said](http://stackoverflow.com/questions/28339000/unzip-zip-files-in-folders-and-subfolders-with-python#comment45037150_28345130): run `pip install pathlib` to install it. On the other hand it is easy to rewrite the code using `os.walk()`, `os.path.join()`, `os.path.splitext()` functions (without `pathlib`). – jfs Feb 08 '15 at 16:41
  • sorry i don't know how to do it, i'm new in python – newGIS Feb 09 '15 at 07:21
  • 1
    it is ok that is why [in the 2nd comment I've suggested that you](http://stackoverflow.com/questions/28339000/unzip-zip-files-in-folders-and-subfolders-with-python#comment45121676_28345130) ask a new question (or read answers to the existing one) e.g.: *"How do I run `pip install pathlib` on [Insert your OS name]?"* To get started, you could complete ["Exercise 0: The Setup" and/or work through "Appendix A: Command Line Crash Course"](http://learnpythonthehardway.org/book/) – jfs Feb 09 '15 at 14:07
  • great i will learn from it- thank's – newGIS Feb 11 '15 at 06:34

0 Answers0