What order does info get returned in by os.listdir()

Miles semanticist at gmail.com
Tue Aug 14 21:31:59 EDT 2007


On 8/14/07, Zentrader wrote:
> On Aug 14, 1:52 pm, Jeremy C B Nicoll wrote:
> > When I use os.listdir() to return that list of leaf values, I do seem to get
> > them in alphabetical order, A before B before C etc, but the ~-prefixed ones
> > are returned after the Z-prefixed files rather than before the A-ones.
>
> I think that os.listdir() returns file names in chronological order,
> that is in the order they were created on disk.

http://docs.python.org/lib/os-file-dir.html
The order is arbitrary, and depends on the underlying directory
structure and system calls.  If you rely on the order being sorted,
you should do it yourself.

-Miles



More information about the Python-list mailing list