Page 1 of 1

Grabbing Folder Names

Posted: Tue Oct 29, 2002 2:02 pm
by Zoram
Hello Everyone! is there a way to get the names of all the folders in a specified directory?

Evilwarlus

Posted: Tue Oct 29, 2002 2:54 pm
by AVATAr

Posted: Tue Oct 29, 2002 4:25 pm
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.

Posted: Wed Oct 30, 2002 2:19 am
by twigletmac
Basically you need to look at these functions:
http://www.php.net/manual/sv/ref.dir.php

Mac