...

View Full Version : removing the "." and ".." when using opendir



mhunt
03-08-2007, 08:25 PM
I currently have a script to list the folders inside of the images folder in a select box. the output source is this:


<select>
<option value="">Select an Album</option>
<option value=".">.</option>
<option value="..">..</option>
<option value="test">test</option>
<option value="test2">test2</option>
</select>



<select name="album">
<option value="">Select an Album</option>
<?
$path = "images/";
$dir_handle = @opendir($path) or die("Unable to open $path");

while($file = readdir($dir_handle)) {
echo "<option value=\"$file\">$file</option>";
}
?>

is there any way to get rid of the <option value=".">.</option><option value="..">..</option>

Alex!
03-08-2007, 08:39 PM
You could use regex providing there isn't going to be a dot in the other options. My regex isn't great but I think it's something like the following:



while($file = readdir($dir_handle))
{
if(!preg_match("/\./", $file))
{
echo "<option value=\"$file\">$file</option>";
}
}


Alex

shyam
03-08-2007, 08:44 PM
/\.\.?/ will match both . and ..

mhunt
03-08-2007, 08:45 PM
haha sweet that worked

Alex!
03-08-2007, 09:01 PM
Glad to hear. And does


/\.+/

match a dot any number of times?

Alex



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum