Re: How to get folders names in a dir
| From: | Justin French | Date: | Wed, 01 Jan 2003 22:51:51 +0000 |
| Subject: | Re: How to get folders names in a dir | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-129880@lists.php.net to get a copy of this message | ||
on 02/01/03 9:36 AM, Alexander Guevara (alexanderguevara@hotmail.com) wrote:
> i need to get in a select box all the dirs inside a folder.. how can i do
> that?
Give this a whirl. Please note, this code is very much slapped together...
it works, and i've tested it, but there's nearly ZERO error checking.
<?
// a function for your library
function getFilesInDir($thedir)
{
chdir($thedir);
$dir = opendir('.');
while (($myfile = readdir($dir)) !==false)
{
if ($myfile != '.' && $myfile != '..' &&
is_file($myfile) )
{
$files[] = $myfile;
}
}
closedir($dir);
chdir('../');
return $files;
}
// get the files in an array
$files = getFilesInDir('../preshrunk/inc/');
// spit out a select box
echo "<form><select name='files'>";
foreach($files as $key => $value) {
echo "<option value='{$value}'>{$value}</option>";
}
echo "</select></form>";
?>
Cheers,
Justin