PHP, read directory contents in reverse order

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
I'm working on a slight modification to my website and want to read the contents of a directory in reverse order. By default, readdir() does it in the order the files appear. Is there a good, preferably easy, way to reverse the order that readdir() works? I'm sure I could come up with a way to get the files in the order I want, but if I can just read them backwards, that'd be a lot easier and more efficient.

Thanks to anyone that can help.
 

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
Thanks, amdfanboy. Doing that or something like it had crossed my mind but I figured I'd check and see if there was an argument or something that could be passed to readdir or something that would do it as the files were read. I guess not. Doesn't matter, though, I can make that work. Thanks.
 

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
Well, couldn't scandir be used? If it returns an array of the files and directories (which can be ignored easily) and had an option for reverse alphabetical order (sort of what I want - I'm using dates, like 05.25.2004 and 08.19.2004 where the August date is later in the "alphabet" than the May date), couldn't I just use that? I think I'll play around with it and see if I can get it to work. That'd be a lot easier than the other way I was thinking I'd have to end up doing it.