Grabbing Folder Names
Moderator: General Moderators
Grabbing Folder Names
Hello Everyone! is there a way to get the names of all the folders in a specified directory?
- AVATAr
- Forum Regular
- Posts: 524
- Joined: Tue Jul 16, 2002 4:19 pm
- Location: Uruguay -- Montevideo
- Contact:
Evilwarlus
search in evilwarlus: http://www.evilwalrus.com/viewcode/366.php
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.
Just drop into the directory you want to see.
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
{
if ($file =="." || $file == ".." || $file =="index.html")continue; // filter files
if (is_file($file))
{
echo "<br>"
."<a href="$testurl$file">$file</a><br>"; //inserts link - - URL address + file
}
}
echo "<p><hr><br>"; // horizontal rule
closedir($dir); // close the directory of the folder
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK