Page 1 of 1

Removing periods in directory listing..

Posted: Mon Mar 29, 2004 9:57 pm
by seeker2921
You know when you view a directory how it looks like this:

.
..
fileone.php
filetwo.php

Well? Using the script below how would I remove the . and .. from showing up on the page with all my other files.. I tried adding them to the exclude array but it didn't work..

Code: Select all

<? 
$maindir = "." ; 
$mydir = opendir($maindir) ; 
$exclude = array( "index.php") ; 
while($fn = readdir($mydir)) { 
if ($fn == $exclude[0] || $fn == $exclude[1]) continue; 
echo "<br><a href='$fn'>$fn</a>"; 
} 
closedir($mydir); 
?>
thanks!

Posted: Mon Mar 29, 2004 10:02 pm
by andre_c
Try:

Code: Select all

<?
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php", "..", ".") ;
while($fn = readdir($mydir)) {
  if (!in_array($fn, $exclude)) {
    echo "<br><a href='$fn'>$fn</a>";
  }
}
closedir($mydir);
?>

Posted: Mon Mar 29, 2004 10:07 pm
by Illusionist

Code: Select all

<?
$maindir = "." ;
$mydir = opendir($maindir) ;
while($fn = readdir($mydir)) {
if ($fn != "index.php" && $fn != "." && $fn != ".."){
echo "<br><a href='$fn'>$fn</a>";
}
}
closedir($mydir);
?>