Share on Google+Share on Google+

PHP list all files in directory

Advertisement
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

Advertisements

Posted on: October 30, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.