3

I was wondering if there was a function equivalent to os.walk() to navigate inside a zipfile. I know that zipfile package provides function to list all content of a zip file, but I was not able to find a way to navigate through the zip file as one would do through a file tree with os.walk().

BayesianMonk
  • 540
  • 7
  • 23
  • No, there is not. – martineau Apr 21 '21 at 16:08
  • You could use the split method to detect dirs like the answer of @Forge on https://stackoverflow.com/questions/36285502/how-to-extract-zip-file-recursively-in-python , but as martineau mentioned there is nothing like os.walk – Kraego Apr 21 '21 at 16:09
  • I saw on the documentation that there is a Path object (for python>=3.8), but I cannot understand what is its purpose. Could this be usefull? – BayesianMonk Apr 21 '21 at 16:15
  • Look at zipfile library, you can read a zip file and then list all entries within the file including directories and subdirectories using namelist(0 method. – itprorh66 Apr 21 '21 at 19:41
  • See Activestate's [Zɪᴘ Wᴀʟᴋᴇʀ](https://code.activestate.com/recipes/425840-zip-walker-zip-file-tree-generator/) recipe (looks like it will need a little updating to work in Python 3.x). – martineau Apr 22 '21 at 18:53

0 Answers0