[Tutor] ok, I want to read a dir.
Michael P. Reilly
Wed, 26 Dec 2001 21:37:15 -0500
On Wed, Dec 26, 2001 at 09:13:56PM -0500, Kirk Bailey wrote:
> ok, it worked. Too well, it worked.
> It returned the file names, and included in the return is the path!
> See, those lines should be the bare name of the thing, a space, then the
> firstline of the info file. Well, ir read the info file pretty slick.
> Accessed the riretory structure just fine. Seems I want to massage the
> elements in the list, or at least in A list, so everything but the first
> part of the file is GONE. Strip off the path, then strip off the .info
> part, leaving us with pure NAME. That name is the name of a list. That
> btw is in my server now, and those are the info files for 3 lists NOW
> working with TLpost.py NOW. snurklechortlegloat...
Then you might want to look at what the glob module is doing. It uses
os.listdir and the fnmatch module.
def nopath_glob(dir, pattern):
import os, fnmatch
files = os.listdir(dir)
results = 
for fname in files:
if fnmatch.fnmatch(fname, pattern):
About the only real difference is that the glob function joins the
directory and file names together first.
This is just the pedantic version.. the same thing is done with