xlistdir -- an iterator version of os.listdir
Andrew Dalke
adalke at mindspring.com
Sun Jan 26 16:57:29 EST 2003
Mongryong wrote:
> It would also be nice to be able to list files allow with a certain
> pattern or suffix.
It's an iterator, so compose it with a filter. Here's one
NOTE: untested!
from __future__ import generators
import fnmatch
def xfnmatchs(filenames, pattern):
for filenames in filenames:
if fnmatch(x, pattern):
yield filename
and you could use this like
for filename in xfnmatches(xlistdir("/etc"), "*.txt")):
if filename.find("spam") != -1:
break
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list