xlistdir -- an iterator version of os.listdir

Grzegorz Adam Hankiewicz gradha at terra.es
Sun Jan 26 11:59:38 EST 2003


> On Sun, 2003-01-26 at 00:17, Terrel Shumway wrote:
> > xlistdir.xlistdir is an iterator version of os.listdir.
>
On Sun, Jan 26, 2003 at 10:35:06AM -0500, Mongryong wrote:
> It would also be nice to be able to list files allow with a certain
> pattern or suffix.

Well, you could filter yourself with fnmatch, here's a usage example:

[gregorio at pedos.es:0] [~]$ python
imporPython 2.2.1 (#1, Apr 21 2002, 08:38:44)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from fnmatch import *
>>> fnmatch("pepe.txt", "*.txt")
1
>>> fnmatch("pepe.tx", "*.txt")
0

Apply that inside the loop and you have your memory minimal custom glob.





More information about the Python-list mailing list