471,319 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Listing directory

I used following code to scan & list directory contents (including all
subdirectories). It turns out that subdirectories are NOT recognized as
directories when the function is called in a recursive way.
In other words when function scans a subdirectory no directories inside are
recognised as directories therefore it cannot scan ti's contents.

<?php
$directory = "/www/prawnik/";
function list_dir($dir) {
if ($handle = opendir($dir)) {
static $indent = 2;
echo "indent=$indent<br>";
echo "dir=$dir<br>";
while (false !== ($file = readdir($handle))) {
if ($file=="." || $file =="..") continue;
if (is_dir($file)=='dir') {
$indent++;
/*
for ($index=1; $index<=$indent; $index++) {
echo "&nbsp&nbsp";
};
*/
echo "<B>$file:".filetype($dir)."</B><br>";
$newdir = $dir.$file."/";
list_dir ($newdir);
$indent--;
} else echo "$indent:$file<br>";
}
closedir($handle);
}
}

list_dir ($directory);
?>
Jul 17 '05 #1
0 1053

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Kim Jensen | last post: by
19 posts views Thread by SU News Server | last post: by
2 posts views Thread by Tom | last post: by
8 posts views Thread by gil | last post: by
2 posts views Thread by ngr | last post: by
8 posts views Thread by dougawells | last post: by
4 posts views Thread by techusky | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.