Warrior Warrior - 6 months ago 14
PHP Question

Listing all the folders subfolders and files in a directory using php

Please give me a solution for listing all the folders,subfolders,files in a directory using php.My folder structure is like this

Main Dir
Dir1
SubDir1
File1
File2
SubDir2
File3
File4
Dir2
SubDir3
File5
File6
SubDir4
File7
File8


I want to get the list of all the files inside each folder.

Is their any shell script command in php ??

Answer
function listFolderFiles($dir){
    $ffs = scandir($dir);
    echo '<ol>';
    foreach($ffs as $ff){
        if($ff != '.' && $ff != '..'){
            echo '<li>'.$ff;
            if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);
            echo '</li>';
        }
    }
    echo '</ol>';
}

listFolderFiles('Main Dir');