A 'find' utility that continues through zipped directory structure?

Fredrik Lundh fredrik at pythonware.com
Tue Sep 27 12:06:22 EDT 2005


"B Mahoney" wrote:

> Is there a Python 'find' -like utility that will continue the file
> search through any zippped directory structure on the find path?

something like this?

# File: zipfind.py
import fnmatch, os, sys, zipfile

program, root, name = sys.argv

for dirpath, dirnames, filenames in os.walk(root):
    for file in fnmatch.filter(filenames, name):
        print os.path.join(dirpath, file)
    for file in fnmatch.filter(filenames, "*.zip"):
        try:
            zip = zipfile.ZipFile(os.path.join(dirpath, file))
        except zipfile.BadZipfile:
            pass # cannot read this file
        else:
            for f in fnmatch.filter(zip.namelist(), name):
                print os.path.join(dirpath, file) + ":" + f

$ python zipfind.py aggdraw "README*"
aggdraw/README
aggdraw/agg2/README.txt
aggdraw/dist/aggdraw-1.1b3-20050925.zip:aggdraw-1.1b3-20050925/README.txt

</F> 






More information about the Python-list mailing list