Voting

: four minus one?
(Example: nine)

The Note You're Voting On

Qwerp
14 years ago
Here's a handy function you can use to list the files in the directory you specify, their type (dir or file) and whether they are hidden.
You could modify it to do other things too.

<?php
function listDirs($where){
echo
"<table border=\"1\"><tr><td><b>Name</b></td><td><b>Type</b></td>";
echo
"<td><b>Invisible (Hidden)?</b></td></tr>";
$itemHandler=opendir($where);
$i=0;
while((
$item=readdir($itemHandler)) !== false){
if(
substr($item, 0, 1)!="."){
if(
is_dir($item)){
echo
"<tr><td>$item</td><td>Directory</td><td>No</td></tr>";
}else{
echo
"<tr><td>$item</td><td>File</td><td>No</td></tr>";
}
$i++;
}else{
if(
is_dir($item)){
echo
"<tr><td>$item</td><td>Directory</td><td>Yes</td></tr>";
}else{
echo
"<tr><td>$item</td><td>File</td><td>Yes</td></tr>";
}
$i++;
}
}
echo
"</table>";
}
?>
Then call it like this.
<?php
listDirs
(DIR);
?>
Example:
<?php
listDirs
("/tests/directorylisting");
?>

You get a table like this.

Name Type Invisible (Hidden)?
. Directory Yes
.. Directory Yes
.DS_Store File Yes
.localized File Yes
index.php File No
OOOLS Directory No
QwerpWiki.php File No

<< Back to user notes page

To Top