<?php

// declare the folder
$ourDir = "/home/public_html/folderName";

// prepare to read directory contents
$ourDirList = @opendir($ourDir);

// loop through the items
while ($ourItem = readdir($ourDirList))
{
   // check if it is a directory
   if (is_dir($ourItem))
   {
      echo "directory: $ourItem <br />";
   }
   // check to see if it is a file
   if (is_file($ourItem))
   {
      echo "file: $ourItem <br />";
   }
}

closedir($ourDirList);

?>

 

source: http://www.aspvphp.com/Code/Text_Files/List_all_Files_and_folders_in_a_Directory.shtml