xlistdir -- an iterator version of os.listdir
altis at semi-retired.com
Sun Jan 26 19:51:08 CET 2003
"The glob module finds all the pathnames matching a specified pattern
according to the rules used by the Unix shell. No tilde expansion is done,
but *, ?, and character ranges expressed with  will be correctly matched.
This is done by using the os.listdir() and fnmatch.fnmatch() functions in
concert, and not by actually invoking a subshell. (For tilde and shell
variable expansion, use os.path.expanduser() and os.path.expandvars().) "
"Mongryong" <Mongryong at sympatico.ca> wrote in message
news:mailman.1043595407.12112.python-list at python.org...
> It would also be nice to be able to list files allow with a certain
> pattern or suffix.
> On Sun, 2003-01-26 at 00:17, Terrel Shumway wrote:
> > xlistdir.xlistdir is an iterator version of os.listdir.
> > It is particularly useful if you have a directory with, for example,
> > 40,000 files, and you only want to look at the first 10.
> > from xlistdir import xlistdir
> > x = xlistdir("directory-with-LOTS-of-files")
> > for i in range(10):
> > print x[i] # or "x.next()"
> > You might also use it to filter the list before allocating it:
> > files_only = [ file for file in xlistdir(bigdir) \
> > if os.path.isfile(os.path.join(bigdir,file)) ]
> > Most of this code was cut and pasted from xreadlinesmodule.c and
> > in Python-2.2.2.tgz
> > This initial hack may not even compile on platforms without
> > opendir/readdir/closedir (e.g. mswin32, mswin16, OS/2) because I do
> > not have access to those platforms.
> > It does include a unit test, and it does pass for me on Linux. 8-)
> > If you can build extension modules on MS_WIN32, MS_WIN16, or OS/2 (or
> > please try this out. If you can make it compile and pass the unit
> > you will get a really cool function to use in your programs and share
> > the rest of the python community 8-).
> > Get the code from http://wxidle.sourceforge.net/projects/xlistdir/
> > -- Terrel
> > --
> > http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list