[Tutor] Reading directory contents (Correction)

tpc at csua.berkeley.edu tpc at csua.berkeley.edu
Fri Aug 29 13:29:52 EDT 2003


hi Mike,
I apologize, there was an error in my last email when I took the code out
of a function and deleted the extra indentation.  The last two lines of
the code paste should be further left, that is, with no indentation.
The corrected version is below:

<code>
APACHE_ROOT_DIR = ''   # you put in your path here
newList = []
def htmlFinder(arg, dirname, fnames):
       for fn in fnames:
               if fn.endswith('.html'):
                       path = os.path.join(dirname, fn)
                       newList.append(path)
os.path.walk(APACHE_ROOT_DIR, htmlFinder, None)
return newList
</code>

On Fri, 29 Aug 2003 tpc at csua.berkeley.edu wrote:

>
> hi Mike, what are you trying to do ?  For what it's worth, I have some
> code that traverses a directory tree recursively, starting at my web
> server document root, and indexes all *.HTML pages.  Not sure if this is
> up your alley:
>
> <code>
> APACHE_ROOT_DIR = ''   # you put in your path here
> newList = []
> def htmlFinder(arg, dirname, fnames):
> 	for fn in fnames:
> 		if fn.endswith('.html'):
> 			path = os.path.join(dirname, fn)
> 			newList.append(path)
> 	os.path.walk(APACHE_ROOT_DIR, htmlFinder, None)
> 	return newList
> </code>
>
> I hope that helps you.
>
> On 29 Aug 2003, Mike Wagman wrote:
>
> > I need some code to load and parse file directories. Can anyone either
> > send me some sample code, or a site that talks about this issue.
> > 	Thanks
> > 	Mike
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>




More information about the Tutor mailing list