Jump to content

scandir - split directories and files?


Sam Granger

Recommended Posts

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

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.
      }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.