Forum Moderators: coopster

Message Too Old, No Replies

list all files

not sure how to do this

         

WhosAWhata

6:02 am on Feb 16, 2005 (gmt 0)

10+ Year Member



i want a file in the root to index all dirs, and subdirs, and subdirs of subdirs, etc.
i would like it to print the path to the file and the file size i just am not sure how to get it to index all subdirs that could strech 10 deep

mincklerstraat

8:21 am on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check out the user-contributed notes to the function readdir() [be2.php.net]. When they're talking about 'ls-recursive', this is what you want. Most of them are recursive (I see one's not, which is pretty cool, I like to avoid recursive functions when I can) which means they are functions that will call themselves - they'll open a directory, read the directory, add the info to an array, and if there's a directory in that directory, they'll call the function for reading that directory. For filesize you can try filesize().

jatar_k

5:26 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



this is from an old thread I posted to but I can't seem to find the original thread

<? 
function display($dir) {
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
$innerstuff = display($ds);
$html .= $innerstuff;
}else{
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>\n";
}
}
}
return $html;
}
echo "<table width=80% cols=2>\n";
$stuff = display("./");
echo $stuff;
echo "</table>\n";
?>

just drop it in the root and call it in a browser