I have a folder and it contains directories in it.Some of the directories contains files and some other contains another directory with its file.What I want is list all the files from the folder.Suppose my folder is A and it contains folder B and C.B contains some mp3 files and in C there is another folder D and in D there are some mp3 files.How it possible to list all mp3 files from B and D.Please help.
Asked
Active
Viewed 940 times
3 Answers
1
function find_all_files($dir)
{
$root = scandir($dir);
foreach($root as $value)
{
if($value === '.' || $value === '..') {continue;}
if(is_file("$dir/$value")) {$result[]="$dir/$value";continue;}
foreach(find_all_files("$dir/$value") as $value)
{
$result[]=$value;
}
}
return $result;
}

pratim_b
- 1,160
- 10
- 29
-
you should include the link of your code source: http://ch2.php.net/scandir – Suresh Kamrushi Dec 11 '13 at 10:15
-
-
-
0
while scanning directory you only want mp3 files. try directory iterator
$scan_it = new RecursiveDirectoryIterator("/example_dir");
foreach(new RecursiveIteratorIterator($scan_it) as $file) {
if (strtolower(substr($file, -4)) == ".mp3") {
echo $file;
}
}
-1
function Read_Dir($dir) {
$dh = opendir($dir);
$files = array();
while (($file = readdir($dh)) !== false) {
$flag = false;
if ($file !== '.' && $file !== '..') {
// check here if file is a directory then use it recursively
$files[] = trim($file);
}
}
return $files;
}
Hope it helps

amarjit singh
- 463
- 5
- 14