'') { // 通常のフィルタ $a = glob($dirPath . "/" . $filter); } else { // フィルタがない場合は dirPath に "/*" を追加 $a = glob($dirPath . "/*"); } } else { // 拡張子フィルタ $exts = preg_split('/:/', $filter); $a = glob($dirPath . "/*"); } $extmatch = false; $n = count($exts); foreach ($a as $f) { if (!is_file($f)) // ファイル以外は処理をスキップ continue; if ($n > 0) { // 拡張子フィルタの場合 for ($i = 0; $i < $n; $i++) { if (preg_match('/\.'.$exts[$i].'$/', $f) === 1) { $extmatch = true; break; } } } if ($full == false) $f1 = File::getFileName($f); else $f1 = $f; if ($n == 0 || ($n > 0 && $extmatch)) { array_push($b, htmlspecialchars($f1)); } } natcasesort($b); // ソート return $b; } // サブディレクトリ一覧を得る。 public static function getSubDirectories($dirPath, $full=false) : array { $b = array(); if (!isset($dirPath)) return $b; $a = glob($dirPath . "/*"); foreach ($a as $f) { if (Directory::exists($f) && ! ($f == "." || $f == "..")) { if ($full == false) { $ss = preg_split('/\//', $f); $f1 = $ss[count($ss) - 1]; array_push($b, htmlspecialchars($f1)); } else array_push($b, htmlspecialchars($f)); } } natcasesort($b); return $b; } // 親のディレクトリを返す。 public function getParentPath(string $dirPath) : string { return dirname($dirPath); } } ?>