Jump to content

php subfolder listing


madspof

Recommended Posts

This will list folders and their nested subfolders
[code]<?php


function listSubFolders ($dir, $level=0) {
    if ($handle = opendir($dir)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir("$dir/$file")) {
                    $indent = str_repeat('---', $level);
                    echo "$indent $file<br>";
                    listSubFolders("$dir/$file", $level+1);  // list subfolders of this folder
                }
            }
        }
        closedir($handle);
    }
}

$dir = 'c:/inetpub/wwwroot';      // <-- specify folder
listSubFolders($dir);
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/19574-php-subfolder-listing/#findComment-85173
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.