Print all files under a directory : Directory « File Directory « PHP






Print all files under a directory


<?php
$dirname = ".";
$dh = opendir($dirname) or die("couldn't open directory");

while (!(($file = readdir($dh)) === false ) ) {
  if (is_dir("$dirname/$file")) {
    echo "(D) ";
  }
  echo $file."<br/>";
}
closedir($dh);
?>

           
       








Related examples in the same category

1.Listing the Contents of a Directory with readdir()
2.Calculate the size for a directory
3.readdir: Read entry from directory handle
4.scandir: List files and directories inside the specified path
5.The current working directory
6.Read the content from a directory
7.Reading Contents from a Directory
8.Clean Path by Regular Expressions