From 788b00f7eaad969120079acedc82e8d60b0e2a46 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 27 Nov 2009 18:00:20 +0000 Subject: non-backwards compatible change to get_dir_file_info() for performance reasons, as well as fixing recursive bug --- system/helpers/file_helper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index cb3d60ee9..41ec2648e 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -220,7 +220,7 @@ if ( ! function_exists('get_filenames')) */ if ( ! function_exists('get_dir_file_info')) { - function get_dir_file_info($source_dir, $include_path = FALSE, $_recursion = FALSE) + function get_dir_file_info($source_dir, $top_level_only = TRUE, $_recursion = FALSE) { static $_filedata = array(); $relative_path = $source_dir; @@ -234,18 +234,20 @@ if ( ! function_exists('get_dir_file_info')) $source_dir = rtrim(realpath($source_dir), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; } + // foreach (scandir($source_dir, 1) as $file) // In addition to being PHP5+, scandir() is simply not as fast while (FALSE !== ($file = readdir($fp))) { - if (@is_dir($source_dir.$file) && strncmp($file, '.', 1) !== 0) - { - get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE); - } - elseif (strncmp($file, '.', 1) !== 0) + if (@is_dir($source_dir.$file) AND strncmp($file, '.', 1) !== 0 AND $top_level_only === FALSE) { + get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $top_level_only, TRUE); + } + elseif (strncmp($file, '.', 1) !== 0) + { $_filedata[$file] = get_file_info($source_dir.$file); $_filedata[$file]['relative_path'] = $relative_path; } } + return $_filedata; } else -- cgit v1.2.3-24-g4f1b