note 59215 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:02:00 +0000 |
| Subject: | note 59215 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126521@lists.php.net to get a copy of this message | ||
Note Submitter: Absynthe
----
This is a function to read all the directories and subdirectories of a folder. It returns an array
with all the paths.
<?PHP
$root = "root";
function arborescence($root)
{
$folders = array();
$path = "$root";
$i = 0;
// Vérification de l'ouverture du dossier
if ($handle = opendir("./".$path))
{
// Lecture du dossier
while ( false !== ($file = readdir($handle)) )
{
if (filetype($path."/".$file) == 'dir')
{
if ($file != '..' && $file != '.' && $file != ''
&& (substr($file,0,1) != '.'))
{
$folders[$i] = "./".$path."/".$file;
$i++;
}
}
}
closedir($handle);
// Recherche de tous les sous dossiers pour chaque dossiers
for ( $u = 0; $u < $i; $u++ )
{
if ($handle = opendir($folders[$u]))
{
// Lecture du dossier
while ( false !== ($file = readdir($handle)) )
{
if (filetype("./".$folders[$u]."/".$file) == 'dir')
{
if ($file != '..' && $file != '.' && $file != ''
&& (substr($file,0,1) != '.'))
{
$folders[$i] = $folders[$u]."/".$file;
$i++;
}
}
}
closedir($handle);
}
}
}
return $folders;
}
?>