By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,970 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,970 IT Pros & Developers. It's quick & easy.

Listing directory

P: n/a
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.

$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') {
for ($index=1; $index<=$indent; $index++) {
echo "&nbsp&nbsp";
echo "<B>$file:".filetype($dir)."</B><br>";
$newdir = $dir.$file."/";
list_dir ($newdir);
} else echo "$indent:$file<br>";

list_dir ($directory);
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.