[Tutor] listdir()
Jeff Shannon
jeff at ccvcorp.com
Fri Jul 2 15:02:28 EDT 2004
Ole Jensen wrote:
> Now, listdir() returns both the files and folders in one big mess, so I
> am wondering if there is some ListFolderInDir() function or similar
> within python that I should use, if so what is its name and location.
> [...]
> But for now I was wondering if there is a simpler way to do? like an
> built in function...
Look into the os.isdir() function, which will tell you easily whether
a given pathname is a directory or not. You will, however, need to do
your own sorting if you want directories to appear before regular
files. (Of course, you'd probably want to sort entries anyhow, since
IIRC the ordering returned by os.listdir() is arbitrary.)
Jeff Shannon
Technician/Programmer
Credit International
More information about the Tutor
mailing list