os.path.walk problem

Steve Holden sholden at holdenweb.com
Mon Aug 12 23:40:11 EDT 2002


"Terry Hancock" <hancock at anansispaceworks.com> wrote in message
news:mailman.1029203179.29313.python-list at python.org...
> Hi all,
>
> This is a weird bug I just came across, and I'm
> wondering how it can happen. I suppose os.path.walk()
> is actually posixpath.walk() since this is on a
> Linux system. I'm running Python 2.1.3.
>
> The program is a bulk-loader for Zope which loads
> a set of files from my Zope product into the ZODB.
> The problem isn't on the Zope side, though, but
> on the part where it tries to read the original
> sources.
>
> What happens is that I get an IOError in the walker
> which complains that I'm trying to read a directory
> as a file  (IOError 21 "Is a directory").  A little
> investigation reveals that this is indeed the case --
> it's trying to read my "CVS" directory.
>
So don't read directories!

> Which is odd, because my understanding is that the
> walker is supposed to be guaranteed to be passed
> a directory path and the list of *regular* files in
> that directory (i.e. the latter list shouldn't
> contain directories). Now I suppose I can fix it by
> testing the files before operating on them, but I
> thought this was pretty odd.  Did I misunderstand
> the documentation on os.path.walk()? Is there some
> normal (or even abnormal) condition under which
> it is expected to let a directory slip through as
> a regular file? Is it relevant that "CVS" is the
> *only* directory in this path?
>
Yes, otherwise your assumption that os.path.walk() does not pass directores
through the list would have more clearly been flagged as erroneous.

The docs for walk() clearly say that the list is gooten with os.listdir(),
whose docs in turn clearly state that it lists the *entries* in the
directory, not just the plain files.

> To make matters worse, this code *works* on the
> FreeBSD server at Imeme, but not on my Linux server
> at home (it's Debian Potato, so kernal 2.2.17, I
> think).  Curiouser and curiouser.
>
The difference wouldn't be the absence of any subdirectories on the FreeBSD
system, would it?

[ ... ]
>
> Any ideas?
>
Just insert a test for subdirectories and ignore them?

regards
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list