reading directory entries one by one

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Tue May 21 13:33:35 EDT 2002


    Greetings. 

    I'm aware that one can iterate over a directory's contents via the
listdir() function in the os module. 

    for file in os.listdir(dir):

    However, this does read in the entire directory into memory. As a C coder,
I can opendir and readdir and iterate the directory file by file, in case
sucking the entire thing into memory would be too resource intensive on large
directories. Is there such an option for Python?

    Thanks,

    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