List Files and Directory inside a Directory

by Sasikumar 2014-05-20 14:23:55

List Files and Directories:
To list the files and directories inside a given directory with full path of the files use the following coding,
function list_directory($directory)
{
    if ($handle = opendir($directory))
    {
        $output = array();
        while (false !== ($item = readdir($handle)))
        {
            if (is_dir($directory.'/'.$item) and $item != "." and $item != "..")
            {
                $output[] = $directory.'/'.$item;
                $output = array_merge($output, list_directory($directory.'/'.$item));
            }
        }
        closedir($handle);
        return $output;
    } else { return false; }
} 

$directory_list = list_directory('directoryname');
foreach($directory_list as $directory) { echo $directory.'
'; }
632
like
0
dislike
0
mail
flag

You must LOGIN to add comments