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

B

B Mahoney

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

Fredrik Lundh

B Mahoney said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top