From 6a4a447c53c4117b0296c7d12dcb0938ebca8fe8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 2 Jun 2005 04:51:34 +0000 Subject: [PATCH] Added scandir() function --- functions.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/functions.php b/functions.php index 646c554..a3919bd 100644 --- a/functions.php +++ b/functions.php @@ -445,6 +445,59 @@ class Functions return 10 * 1048576; } } + + /** + * Scans a specified directory path and returns an array of all the itmes in that directory. Directories found by this are end in a "/" + * + * @param str Path to scan + * @param bool Whether or not to recursively scan the directories encountered + * @param bool Ignore files beginning with a dot + * @param bool Ignore 'CVS' dirctories + * + * @return array A list of all the files in the specified path + */ + function scandir($path, $recurse = true, $ignoredot = true, $ignorecvs = true, $basepath = '', $unset = 1) + { + static $filelist; + + if ($unset) + { + $filelist = array(); + } + + if (substr($path, (strlen($path) - 1), 1) != '/') + { + $path .= '/'; + } + + if ($handle = opendir($path)) + { + while (($file = readdir($handle)) !== false) + { + $isdot = ((substr($file, 0, 1) == '.') ? true : false); + $isdot = (($ignoredot) ? $isdot : true); + $iscvs = (($file == 'CVS') ? true : false); + $iscvs = (($ignorecvs) ? $iscvs : true); + if (!$isdot AND !$iscvs) + { + if (is_dir($path . $file)) + { + $filelist["$basepath"][] = "$file/"; + if ($recurse) + { + $this->scandir("$path$file", true, $ignoredot, $ignorecvs, "$basepath$file/", 0); + } + } + else + { + $filelist["$basepath"][] = $file; + } + } + } + closedir($handle); + } + return $filelist; + } } /*=====================================================================*\ -- 2.43.5