* @param string 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
*/
- public static function ScanDirectory($path, $recurse = true, $ignoredot = true, $ignorecvs = true, $basepath = '', $unset = 1)
+ public static function ScanDirectory($path, $recurse = true, $ignoreDot = true)
{
- static $filelist;
-
- if ($unset)
- {
- $filelist = array();
- }
-
- if (substr($path, (strlen($path) - 1), 1) != '/')
- {
- $path .= '/';
- }
+ return self::_helpScanDirectory($path, $recurse, $ignoreDot, '');
+ }
+
+ // ###################################################################
+ /**
+ * Scans a specified directory path and returns an array of all the
+ * items in that directory. Directories found by this are end in a "/"
+ *
+ * @param string Path to scan
+ * @param bool Whether or not to recursively scan the directories encountered
+ * @param bool Ignore files beginning with a dot
+ * @param string Add to the beginning of the path
+ *
+ * @return array A list of all the files in the specified path
+ */
+ private static function _helpScanDirectory($path, $recurse = true, $ignoreDot = true, $pathAdd = '')
+ {
+ $filelist = array();
+ $path = self::FetchSourcePath($path);
- if ($handle = opendir($path))
+ $dir = new DirectoryIterator($path);
+ foreach ($dir AS $file)
{
- while (($file = readdir($handle)) !== false)
+ $name = $file->getFilename();
+ if (($file->isDot() OR $name[0] == '.') AND $ignoreDot)
{
- $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)
- {
- self::ScanDirectory("$path$file", true, $ignoredot, $ignorecvs, "$basepath$file/", 0);
- }
- }
- else
- {
- $filelist["$basepath"][] = $file;
- }
- }
+ continue;
+ }
+
+ if ($file->isDir() AND $recurse)
+ {
+ $filelist = array_merge($filelist, self::_helpScanDirectory($path . $name, $recurse, $ignoreDot, $pathAdd . BSFunctions::FetchSourcePath(str_replace($path, '', $file->getPathname()))));
+ continue;
}
- closedir($handle);
+
+ $filelist[] = $pathAdd . $name;
}
+
return $filelist;
}