Home Tutorial Php List PHP list all files in directory

 
 

PHP list all files in directory
Posted on: October 30, 2009 at 12:00 AM
In this tutorial we will learn to list all the files and directories in the given directory name.

  • Using the readdir() and opendir() function all files of the directory can be listed.
  • readdir() function uses the file handler of the readdir() function.
  • It then returns the filename of the directory.


Example

<?php
    $file
=opendir("c:/apache-tomcat-6.0.16");
     while
($a=readdir($file))
       {
        echo
$a."<br>";
       }
?>

Output
.
..
bin
conf
lib
LICENSE
logs
NOTICE
RELEASE-NOTES
RUNNING.txt
spring1.war
temp
webapps
work

Related Tags for PHP list all files in directory:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.