reading directory entries one by one
Michael P. Soulier
msoulier at nortelnetworks.com_.nospam
Wed May 22 09:23:10 EDT 2002
On Wed, 22 May 2002 10:21:47 GMT, Michael Hudson <mwh at python.net> wrote:
>
> How big are your directories? I'd be surprised to find this was ever
> an issue, but...
I have a few with 4000+ files in them. There's enough memory on the box to
easily handle this, but it's still not efficient.
> Don't think so. Wouldn't be that hard, though you'd have to write
> some C. Hmm, might be a cool application of iterators.
>
> Hmm, thinking aloud, would it be possible/nice to be able to do:
>
> for entry in dir("/"):
> if entry.isdir():
> print "skipping", entry.basename
> elif entry.islink():
> print entry.readlink()
> else:
> print entry.basename, len(entry.open('r').read())
Perhaps an xlistdir (lazy version) is in order. Maybe I'll go play with
this, to teach myself how to extend python.
> ... Windows proponents tell you that it will solve things that
> your Unix system people keep telling you are hard. The Unix
> people are right: they are hard, and Windows does not solve
> them, ... -- Tim Bradshaw, comp.lang.lisp
:) I like your .sig. Personally the direction that some of python is
taking towards windows-lovers bothers me, but it's still a great language. I
mean, c'mon, .ini file format for the configparser?
<side_rant>
And who created file() as an alias for open()? I really prefer to not get too
far away from the Unix API in the naming of functions. I have to write C too,
and it makes things far easier to find the equivalent function in python that
I'm looking for when it has the same name.
</side_rant>
Ah, better. :)
Mike
--
Michael P. Soulier, QX41, SKY Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort." -Harley Hahn, A Student's Guide to Unix
More information about the Python-list
mailing list