map200uk Posted April 22, 2007 Share Posted April 22, 2007 hi, as asked before, im having troubles with my recursive directory scan <?php function recur_dir($dir) { $dirlist = opendir($dir); while ($file = readdir ($dirlist)) { if ($file != '.' && $file != '..') { $newpath = $dir.'/'.$file; $level = explode('/',$newpath); if (is_dir($newpath)) { $parts=pathinfo($newpath); $extension=$parts['extension']; recur_dir($newpath); }else{ $parts=pathinfo($newpath); $extension=$parts['extension']; if($extension=="mp3") { echo "mp3 found, file : => $newpath"; $mp3[]=$newpath; } echo "<br>File \n $newpath has extension equal to $extension<br>"; } } } echo "<br><br><br><br>"; print_r($mp3); closedir($dirlist); return $mod_array; } echo '<pre>'; print_r(recur_dir('.')); echo '</pre>'; recur_dir("/home/map/www.vcd.cl"); ?> when an mp3 is found i need it to add the entry to an array, and then this array would get returned containing all the found mp3s, altho i cannot seem to get it to work?! help greatly appreciated mark Link to comment https://forums.phpfreaks.com/topic/48140-recursive-dir-scan-someone-help/ Share on other sites More sharing options...
Glyde Posted April 22, 2007 Share Posted April 22, 2007 <?php function findMusic($dir) { $musicList = array(); $dirHandle = opendir($dir); while (($file = readdir($dirHandle)) !== FALSE) { if ($file == "." || $file == "..") continue; if (is_dir($dir . "/" . $file)) $musicList = array_merge($musicList, findMusic($dir . "/" . $file)); else { $extension = end(explode(chr(46), $file)); print $extension; if (strtolower($extension) == "mp3") { $musicList[] = $dir . "/" . $file; } } } closedir($dirHandle); return $musicList; } print_r(findMusic("C:/Documents and Settings/Your Username/My Documents/My Music")); ?> Made a slight mistake in the first code. So, if you copied it before my last edit time in this post, try copying it again before you post that it doesn't work . Link to comment https://forums.phpfreaks.com/topic/48140-recursive-dir-scan-someone-help/#findComment-235264 Share on other sites More sharing options...
map200uk Posted April 24, 2007 Author Share Posted April 24, 2007 Thanks a lot mate:> Sorry Mark, Link to comment https://forums.phpfreaks.com/topic/48140-recursive-dir-scan-someone-help/#findComment-236619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.