Listing files in directory and files in sub directory

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Listing files in directory and files in sub directory

Post by winsonlee »

How am I able to list the files in directories and sub directory using glob function ??
If i am not wrong glob can only list files in the particular directory but not all the files in the subdirectory.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why did you create a new thread on this?

There is a thread in Code Snippets (I believe) regarding the creation of a directory tree. It may be of interest.
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

well

Post by akimm »

If you haven't found the code snipplet yet I can give you an idea how use glob()

Code: Select all

<table>
<tr>
<?php
foreach (glob("sample_dira/sample_dirb/*.php") as $dir) {
     echo '<td>' . $dir . '</td>';
}
?> 
</tr></td>
User avatar
akimm
Forum Contributor
Posts: 460
Joined: Thu Apr 27, 2006 10:50 am
Location: Ypsilanti Michigan, formally Clipsburgh

Post by akimm »

And this will list the contents of the dir as a link

Code: Select all

<?php
foreach (glob(sample_dir/sample_dir/"*.*") as $filename) 
{
   echo "<a href=\"".$filename."\">".$filename."</a><br/>";
}
?>
Post Reply