As others have said, in the method itself you need to call getFilesNFolders with $this -> getFilesNFolders($file). Also, the way the code was sent at the end is missing at the end, but since it starts after the code, it is probably a typo. The following code worked for me (I ran through the command line, so I added code for indenting different levels of directories, as well as \ n's output):
<?php
class StyleFinder{
function StyleFinder(){
}
function getFilesNFolders($folder, $spaces){
$this->folder = $folder ;
if($this->folder==""){
$this->folder = '.';
}
if ($handle = opendir($this->folder)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($file)){
echo $spaces . "<b>" . $file . " is a folder</b><br/> with contents:\n";
$this -> getFilesNFolders($file, $spaces . " ");
} else {
echo $spaces . "$file<br />\n";
}
}
}
closedir($handle);
}
}
}
$sf = new StyleFinder();
$sf -> getFilesNFolders(".", "");
?>
source
share