skip certain file in readdir();

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

skip certain file in readdir();

Post by glennn3 »

got this readdir() function:

Code: Select all

function listfiles($directory, $select_name, $selected = "") {
   if ($dir = @opendir("/home/ensign/public_html/prose")) {
       while (($file = readdir($dir)) !== false) {
           if ($file != ".." && $file != ".") {
               $filelistї] = $file;
           }
       }
           closedir($dir);
   }
   echo "<select name="filename">";
   asort($filelist);
   while (list ($key, $val) = each ($filelist)) &#123;
       echo "<option value="$val"";
       if ($selected == $val) &#123;
           echo "selected";
       &#125;
       echo ">$val</option>";
   &#125;
   echo "</select>";
&#125;
listfiles ($key, $val);
but i need to skip one file within this dir (file.php) so that it's not returned to the select field...

anyone?

thanks
glenn
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Easy:

Code: Select all

<?php
           if ($file != ".." && $file != "." && $file != "filename.php") {
               $filelist[] = $file;
           }
?>
Just replace "filename.php" with whatever file you don't want to include.
glennn3
Forum Commoner
Posts: 63
Joined: Sat Sep 20, 2003 8:43 pm

thanks

Post by glennn3 »

thanks, duff - you're the man.

g
Post Reply