Page 1 of 1

Readdir(), dot's

Posted: Sat Aug 17, 2002 3:14 pm
by Zeceer
When I use readdir() with loops I always get this enoying dot's on the top. Think everyone know what i mean? Anyway to remove this dot's?

Posted: Sat Aug 17, 2002 5:05 pm
by hob_goblin
should have been asked in php, but they represent folders

../ is the folder above the current folder
./ is the folder itself


usually you would check before the files are listed that they do not equal ".." or "."

Posted: Sat Aug 17, 2002 6:41 pm
by Zeceer
I know, I posted in the forum forum. Sorry :oops: . But is it possible to not show these? Hide them or remove them in some way?

Posted: Sat Aug 17, 2002 8:15 pm
by volka
i.e.
if ($filename != '.' && $filename != '..')
{ /* display */ }

Posted: Sat Aug 17, 2002 8:46 pm
by hob_goblin
if you posted the script you are using i would gladly incorporate something to remove these dots.

(if you dont understand what volka did)

Posted: Sun Aug 18, 2002 5:26 am
by Zeceer
I tried using what volvo did, but it didn't go to well :wink: . I understand what he did, and tried doing this my self by making an if() that checks if any of the filenames are . or .., but I didn't get it to remove the dot's.

Code: Select all

<?php

$dirnavn = "../produkter";
$opendir = opendir( $dirnavn );

while( $file = readdir( $opendir ) )
       &#123;
             print('<input type="radio" name="'."slett".'" value="'."$file".'">'."$to_start$file$to_end<br>\n");
       &#125;

?>

Posted: Sun Aug 18, 2002 7:31 am
by MattF

Code: Select all

<?php

$dirnavn = "../produkter";
$opendir = opendir( $dirnavn );

while( $file = readdir( $opendir ) )
       &#123;
       if($file != "." || $file != "..") &#123;
           echo "<input type="radio" name="slett" value="".$file."">".$to_start.$file.$to_end."<br>\n";
       &#125;
       &#125;

?>

Posted: Sun Aug 18, 2002 10:49 am
by Zeceer
Well, thats what i've tried :D . I used you're example to, but it still display the dot's. Just have to live with them I suppose?

Posted: Sun Aug 18, 2002 2:01 pm
by fatalcure

Code: Select all

<?php 

$dirnavn = "../produkter"; 
$opendir = opendir( $dirnavn ); 

while (($file = readdir($opendir)) !== false) &#123;
		if ($file != "." && $file != "..") &#123;
          echo "<input type='radio' name='slett' value='$file'>$to_start$file$to_end<br>\n"; 
     &#125;
&#125;
closedir($opendir);

Posted: Sun Aug 18, 2002 2:18 pm
by volka
(in addition to the last post)
it must be unequal to '.' AND '..'
So the logical operator is &&, not || which would mean the filename must be unequal to either '.' or '..' (what every filename is ;) )