note 56379 modified in function.scandir by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Jan 2010 14:19:48 +0000 |
| Subject: | note 56379 modified in function.scandir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165455@lists.php.net to get a copy of this message | ||
<?php
/**********************************************
*
* PURPOSE: List files inside the specified path and its
* subdirectories
*
* array scandir_recursive (string dir)
*
* This function will return a multidimensional array
* that represents main folder's tree structure.
* Each folder has its own named array
*
**********************************************/
function scandir_recursive($directory)
{
$folderContents = array();
$directory = realpath($directory).DIRECTORY_SEPARATOR;
foreach (scandir($directory) as $folderItem)
{
if ($folderItem != "." AND $folderItem != "..")
{
if (is_dir($directory.$folderItem.DIRECTORY_SEPARATOR))
{
$folderContents[$folderItem] = scandir_recursive(
$directory.$folderItem."\\");
}
else
{
$folderContents[] = $folderItem;
}
}
}
return $folderContents;
}
?>
--was--
/**********************************************
*
* PURPOSE: List files inside the specified path and its
* subdirectories
*
* array scandir_recursive (string dir)
*
* This function will return a multidimensional array
* that represents main folder's tree structure.
* Each folder has its own named array
*
**********************************************/
function scandir_recursive($directory)
{
$folderContents = array();
$directory = realpath($directory).DIRECTORY_SEPARATOR;
foreach (scandir($directory) as $folderItem)
{
if ($folderItem != "." AND $folderItem != "..")
{
if (is_dir($directory.$folderItem.DIRECTORY_SEPARATOR))
{
$folderContents[$folderItem] = scandir_recursive(
$directory.$folderItem."\\");
}
else
{
$folderContents[] = $folderItem;
}
}
}
return $folderContents;
}
http://php.net/manual/en/function.scandir.php