Finally were going to look at a function that uses recursion to move though a Zip file and its sub archives; returning a complete list of all none Zip files. But what’s the point in this? Let's say for instance that you want to count the number of files in a Zip, this way all you have to do is call len() on our function. Enough talk lets see this function in action.
But wait, there's... uhm... nevermind. That's it. Sorry if I hyped that last one up a bit. Unlike our other examples rezipe() opens the Zip file itself instead of using one we’ve already opened. It then loops though zip.namelist() and if name ends with .zip we extract it to the current working directory and call rezipe() on it, removing it when rezipe() is complete. The next part simply says if name isn’t a Zip file or a folder append it to the end of our list. If your anything like me by now I’m sure you can see the potential this little guy (in particular) has and what this means for your Zip files! If you’ve found this article interesting and you want to learn more about Python or some of the subjects covered here: http://www.python.org/ - Python homepage Note: All the examples shown and discussed in this article where tested on Windows XP with Python 2.3 and are meant only as examples.
blog comments powered by Disqus |