Kingy Posted February 13, 2008 Share Posted February 13, 2008 I am trying to read all directories within a certain directory and list all the files... the code i have at the moment only lists the main directory.. eg MainDirectory - dir - dir -file -file -file -file what i would like it to do is. MainDirectory - dir --file --file - dir --file --file -file -file -file -file Link to comment https://forums.phpfreaks.com/topic/90985-read-multiple-directories/ Share on other sites More sharing options...
Kingy Posted February 13, 2008 Author Share Posted February 13, 2008 i jumped the gun a bit and forgot to put in my code lol <?php mysql_connect("localhost", "root", "kwcm92fs"); mysql_select_db("server"); $dir = "./../layout/"; // Open a known directory, and proceed to read its contents if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(($file == ".") || ($file == "..")) { } else { $filetype = explode(".", $file); $type = filetype($dir . $file); $size = filesize($dir . $file); $change = date("d/m/Y H:i:s", filectime($dir . $file)); echo "<b>filename:</b> $file : <b>type:</b> $type <b>filechanged:</b> $change <br />"; } } closedir($dh); } } ?> Link to comment https://forums.phpfreaks.com/topic/90985-read-multiple-directories/#findComment-466311 Share on other sites More sharing options...
Daniel0 Posted February 13, 2008 Share Posted February 13, 2008 Make a recursive function. <?php function readDir($dir) { $items = scandir($dir); foreach($items as $item) { if(in_array($item, array('.', '..'))) continue; echo $dir, $item, "\n"; if(is_dir($item)) readDir($dir . $item); } } readDir('/home/daniel'); ?> Link to comment https://forums.phpfreaks.com/topic/90985-read-multiple-directories/#findComment-466318 Share on other sites More sharing options...
Kingy Posted February 13, 2008 Author Share Posted February 13, 2008 PHP Fatal error: Cannot redeclare readdir() on line 11 Link to comment https://forums.phpfreaks.com/topic/90985-read-multiple-directories/#findComment-466325 Share on other sites More sharing options...
Daniel0 Posted February 13, 2008 Share Posted February 13, 2008 Oh... yeah... forgot there was a library function called that :-\ Just call it something else. Link to comment https://forums.phpfreaks.com/topic/90985-read-multiple-directories/#findComment-466326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.