[Tutor] sorting os.listdir.

Thomas CLive Richards thomi@thomi.imail.net.nz
Thu May 15 07:48:21 2003


IS there a reason os.listdir doesn't sort it's output? It does seem a little silly.

What I'm trying to do now is write a little wrapper function, while will look like this:

def listdirectory (path,sort="alphanumeric"):
	blah blah blah


this function will call os.listdir, and then sort through the output, according to the sort parameter. possible sort parameters should include alphanumeric, numeric, ascii (just takes the ascii values of the charecter).

Does anyone have any good ideas about how to implement this in an efficient manner? It's going to go in a CGI program which has to list a whole heap of files, so speed and memory usage is a slight issue.

hmmm.. isn't there some sort of builtin sort() function somewhere?? only it's not in the builtins section of the docs.... or maybe that was some other language... bah.. too tired :-)

-- 

Thomi Richards,
thomi@thomi.imail.net.nz