I saw a website a couple of weeks, which was taking almost an hour to load b/c it was going through a quite big hierarchy of files in a folder under the www directory.
That sounds like it also might be an i/o issue on top of the overly simply directory scanning. Can't hurt to test this code on there to see if there is an improvement or if further code is required for that type of site.