Readdir(), dot's

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
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Readdir(), dot's

Post 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?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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 "."
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

i.e.
if ($filename != '.' && $filename != '..')
{ /* display */ }
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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)
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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;

?>
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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;

?>
User avatar
Zeceer
Forum Contributor
Posts: 136
Joined: Fri Aug 02, 2002 5:10 am
Location: Norway

Post 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?
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post 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);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 ;) )
Post Reply