--- ./includes/file.inc	2007-10-18 08:33:00.000000000 -0700
+++ ./includes/file.inc	2007-10-22 12:18:05.864183200 -0700
@@ -885,9 +885,11 @@ function file_scan_directory($dir, $mask
     while ($file = readdir($handle)) {
       if (!in_array($file, $nomask) && $file[0] != '.') {
         if (is_dir("$dir/$file") && $recurse) {
-          $files = array_merge($files, file_scan_directory("$dir/$file", $mask, $nomask, $callback, $recurse, $key, $min_depth, $depth + 1));
+          // Make the recursive call and only add matches that don't already exist in $files.
+          $files = array_merge(file_scan_directory("$dir/$file", $mask, $nomask, $callback, $recurse, $key, $min_depth, $depth + 1), $files);
         }
         elseif ($depth >= $min_depth && ereg($mask, $file)) {
+          // Always use this match over anything already set in $files.
           $filename = "$dir/$file";
           $basename = basename($file);
           $name = substr($basename, 0, strrpos($basename, '.'));
