<?php function CountDir($aDir, $aRecurse) { $Count = 0; $d = dir($aDir); while ($Entry = $d->Read()) { if (!(($Entry == "..") || ($Entry == "."))) { if (Is_Dir($aDir . '/' . $Entry)) { if ($aRecurse) { $Count += CountDir($aDir . '/' . $Entry, $aRecurse); } } else { $Parts = explode(".", $Entry); if (pop($Parts) == "txt") { $Count++; } } } } return $Count; } ?>
echo CountDir($_SERVER["DOCUMENT_ROOT"], True); // Echo's 9 echo CountDir($_SERVER["DOCUMENT_ROOT"], False); // Echo's 3
<?php function CountDir($aDir, $aRecurse) { $Count = 0; $d = dir($aDir); while ($Entry = $d->Read()) { if (!(($Entry == "..") || ($Entry == "."))) { if (Is_Dir($aDir . '/' . $Entry)) { if ($aRecurse) { $Count += CountDir($aDir . '/' . $Entry, $aRecurse); } } else { # $Parts = explode(".", $Entry); // Comment this line # if (pop($Parts) == "txt") // Replace this code if (preg_match ("/.txt/i",$Entry)) { $Count++; } } } } return $Count; } echo CountDir($_SERVER["DOCUMENT_ROOT"], True); // Echo's 9 ?>
preg_match ( "/\d+\.txt/i", $Entry )