Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.190
diff -u -r1.190 file.inc
--- includes/file.inc	31 Aug 2009 05:47:33 -0000	1.190
+++ includes/file.inc	27 Sep 2009 04:31:44 -0000
@@ -1596,10 +1596,13 @@
     'recurse' => TRUE,
     'key' => 'uri',
     'min_depth' => 0,
+    'max_depth' => 0
   );
 
   $options['key'] = in_array($options['key'], array('uri', 'filename', 'name')) ? $options['key'] : 'uri';
   $files = array();
+  if ($options['max_depth'] && $depth >= $options['max_depth']) { return $files; }
+
   if (is_dir($dir) && $handle = opendir($dir)) {
     while (FALSE !== ($filename = readdir($handle))) {
       if (!preg_match($options['nomask'], $filename) && $filename[0] != '.') {
