Introduce wp_scandir, remove opendir / closedir code

Description

There is @opendir code all over the place that is not standardized. On top of that, there is plenty of code that is duplicated and could be condensed into one handy function. Plus, in all of the places we are using opendir(), we really want to be using scandir().

I have created a master function in load.php called wp_scandir() that does the basics: