Page 1 of 1

Directory List - Strip Files

Posted: Sat Apr 15, 2006 5:56 pm
by mad687
I'm trying to create a script that lists out directories in a <select> dropdown. I've figured out how to list a complete directory (script below), but now I have to figure out how to remove all of the files (I only need the directories). Any tips?

Thanks,
Marcus

Code: Select all

<select>
<?
    $path = "/home/kinetici/public_html/pbluff/test single file/download/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {

    if($file == "." || $file == ".." || $file == "index.php" )

        continue;
        echo "<option value=\"$file\">$file</option>";

    }

    // Close
    closedir($dir_handle);

?>
</select>

Posted: Sat Apr 15, 2006 5:59 pm
by feyd

Worked! Thanks

Posted: Sat Apr 15, 2006 6:21 pm
by mad687
Ok thanks, that worked.

Just in case someone ever needs this code heres the working version:

Code: Select all

<select name="lot">
<?
    $path = "/home/kinetici/public_html/pbluff/test single file/download/";
    $dir_handle = @opendir($path) or die("Unable to open $path");
    while ($file = readdir($dir_handle)) {

    if($file == "." || $file == ".." || $file == "index.php" || $file != is_dir($path . $file) )

        continue;
        echo "<option value=\"$file\">$file</option>";

    }

    // Close
    closedir($dir_handle);

?>
</select>