Php - Script to list directory and its files, List folder sub folder and its file


Script to list directory and its files

function ListFiles($dir) 
{
if($dh = opendir($dir)) 
{
$files = Array();
$inner_files = Array();
while($file = readdir($dh)) 
{
if($file != "." && $file != ".." && $file[0] != '.') 
{
if(is_dir($dir . "/" . $file)) 
{
$inner_files = ListFiles($dir . "/" . $file);
if(is_array($inner_files)) 
$files = array_merge($files, $inner_files); 
} 
else 
{
array_push($files, $dir . "/" . $file);
}
}
}
closedir($dh);
return $files;
}
}

foreach (ListFiles('../modules') as $key=>$file) // Enter Dir name!
{
echo $file ."
";
}
Php to script to list the directories, sub-directories and its files. This script helps you to list the folder and file.
Php - List folder sub folder and its file
The topic on Php - Script to list directory and its files is posted by - Maha
Hope you have enjoyed, Php - Script to list directory and its files . Thanks for your time.

All rights reserved. © www.w3calculator.com