Page 1 of 1

i get dots with readdir() results

Posted: Sat Mar 01, 2003 1:19 pm
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 :?

Posted: Sat Mar 01, 2003 1:35 pm
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 />';
}

Posted: Sat Mar 01, 2003 1:58 pm
by VisionsOfCody
Hi Volka
Thanks for your reply and the bit of code.
I think i'll be coming back here more often :D