Jump to content

Listing files in directories and its sub-directories


ylkien

Recommended Posts

Hi all,

I created this simple code to list everything in a folder. Your feedback is utmost appreciated!

[code]
function Get_Directory_Listing( $dir )
{

if( is_dir( $dir ) )
{
//This is added so that it can enter & list the sub-directories nicely
if( (substr( $dir, -1) !== "/") || (substr( $dir, -1) !== "\\") )
$dir .= "\\";

//This is the main function, whereby it enters the folders and list their contents
if( $dir_open = opendir( $dir ) )
{
while( ( $file = readdir( $dir_open ) ) !== false )
{
if( $file == "." || $file == ".." )
continue;

if( filetype( $dir . $file ) == "dir")
{
echo "<BR><BR><b>Directory found : $dir$file </b>";
//if( substr(
Get_Directory_Listing( $dir . $file  );
}
echo "<BR>Filename : $file,  filetype : " . filetype( $dir . $file );
}
}
closedir( $dir_open );
}
else
{
//This is incase the user forgets to put the semicolon after the drive letter
$dir .= ":";
echo "<BR>Drive to be listed : $dir";
Get_Directory_Listing( $dir );
}
}
[/code]

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.