Working with Directories
resource opendir ( string path )
bool is_dir ( string path )
string readdir ( resource dir_handle )
void closedir ( resource dir_handle )
array scandir ( string directory [, int sorting_order [, resource context]] )
<?php
function numfilesindir ($thedir){
if (is_dir ($thedir)){
$scanarray = scandir ($thedir);
for ($i = 0; $i < count ($scanarray); $i++){
if ($scanarray[$i] != "." && $scanarray[$i] != ".."){
if (is_file ($thedir . "/" . $scanarray[$i])){
echo $scanarray[$i] . "<br />";
}
}
}
} else {
echo "Sorry, this directory does not exist.";
}
}
echo numfilesindir ("sample1");
?>
<?
$handle = opendir('/path/to/directory')
if ($handle) {
while (false != = ($file = readdir($handle))) {
print "$file<br />\n";
}
closedir($handle);
}
?>
Related examples in the same category