i get dots with readdir() results

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
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

i get dots with readdir() results

Post by VisionsOfCody »

Hi
I'm a new newbie so forgive me if i'm posting in the wrong slot :D

My problem is that when i use readdir() to give me a list of the folders in my base directory, the first two lines are dots before the real results, like this:

.
..
folder1
folder2
folder3


what's the reason for this and how can i get round it??
thanks for any enlightenment :?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

. and .. are special directories you will find almost everywhere.
. points to the same directory as the current working directory and .. points to the next directory above (e.g. in /home/UserA .. points to /home on a unix-style system and in c:\winnt\system32 .. points to c:\winnt on a win32-system).
if you want to get rid of them in the output test wether the filename is unequal to . and ..

Code: Select all

$dd = opendir($path);
while($fname = readdir($dd))
{
	if ($fname != '.' && $fname != '..')
		echo $fname, '<br />';
}
Last edited by volka on Sat Mar 01, 2003 2:00 pm, edited 1 time in total.
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

Post by VisionsOfCody »

Hi Volka
Thanks for your reply and the bit of code.
I think i'll be coming back here more often :D
Post Reply