Sam Granger Posted April 12, 2008 Share Posted April 12, 2008 First of all, thanks for having a look here! I appreciate it. <?php foreach(scandir($scandirectory) as $dirName) { echo ' <li><a href="' . $location . 'browse:' . $dirName . '/">' . $dirName . '</a></li>' . PHP_EOL; } ?> I have managed to create the code above. This outputs all directories and files in a certain directory. I want to make 2 foreach statements. One for directories only and one for files only. How would I go around doing this? Would I be better off using glob? What are the differences? Looking forward to your replies! Thanks, Sam Link to comment https://forums.phpfreaks.com/topic/100785-scandir-split-directories-and-files/ Share on other sites More sharing options...
doni49 Posted April 13, 2008 Share Posted April 13, 2008 The closest thing I can think of is to use an if statement in this loop. <?php foreach(scandir($scandirectory) as $dirName) { if(is_file){ //process as a file. echo ' <li><a href="' . $location . 'browse:' . $dirName . '/">' . $dirName . '</a></li>' . PHP_EOL; }else{ //process as a directory. } } ?> Link to comment https://forums.phpfreaks.com/topic/100785-scandir-split-directories-and-files/#findComment-515825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.