Grabbing Folder Names

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
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Grabbing Folder Names

Post by Zoram »

Hello Everyone! is there a way to get the names of all the folders in a specified directory?
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Evilwarlus

Post by AVATAr »

ssand
Forum Commoner
Posts: 72
Joined: Sat Jun 22, 2002 9:25 pm
Location: Iowa

Post by ssand »

I use this to grab the files in a directory. You could just change out the is_file to is_dir then you would get only the directories instead only files.

Code: Select all

<?
	$current_dir="/usr/local/apache/htdocs/"; 							// full server path to folder
	$dir=opendir($current_dir);  										    // open directory of the folder
	$testurl="http://www.stevesand.com/";		    					// URL of folder to access

	echo "<hr>"; 									    			     	// horizontal rule inserted

	while ($file=readdir($dir))											// begins to read directory
	&#123;
		if ($file =="." || $file == ".." || $file =="index.html")continue; // filter files
		
		if (is_file($file))
		&#123;
		echo "<br>"
			."<a href="$testurl$file">$file</a><br>"; 				//inserts link - - URL address + file
		&#125;
	&#125;

	echo "<p><hr><br>";													// horizontal rule
	closedir($dir);														// close the directory of the folder

?>
Just drop into the directory you want to see.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Basically you need to look at these functions:
http://www.php.net/manual/sv/ref.dir.php

Mac
Post Reply