Friday, 16 August 2013

Loop Through Entire Directory php

Loop Through Entire Directory php

I can loop through a directory and one subfolder like this
$directoryArray = scandir('../portalFolders/');
foreach($directoryArray as $directory){
$listString .='
<li class="closed"><span
class="folder">'.$directory.'</span>';
$subDirectoryArray = scandir('../portalFolders/'.$directory);
$howManyFolders = $subDirectoryArray -> count();
if($howManyFolders > 0){
$listString .= '<ul>';
foreach($subDirectoryArray as $subDirectory){
$listString .= '<li class="closed"><span
class="folder">'.$subDirectory.'</span><li>';
}
$listString .= '</ul>';
}
else{
$listString .= '</li>';
}
}
How Can I make it search/loop through ALL of the child directories of the
sub directories without me nesting another foreach()? This way, I can add
as many folders/subfolders as I want via FTP and not have to make the nest
deeper in the code.

No comments:

Post a Comment