Open and read a directory with readdir()

.
..
externalPHP.php
ch_11
181_fseek.php
177_touchCreateFile.php
test.txt
listing10_2.php
180_fread.php
readFile.php
incfile3.txt
185_readdir.php
170b_include.php
182_fgetc.php
174_checkFileStatus.php
incfile2.txt
Listing10_7.php
fread.php
incfile1.txt
175_fileDateInfo.php
183_fwrite.php
179_fgets.php
170_include.php
test2.txt
test.dat
176_multipleFileTestFunc.php
$dirname = "."; 
$dh = opendir( $dirname ) or die("Couldn't open $dirname");
while (!(($file = readdir($dh)) === false {
    if ( is_dir("$dirname/$file"))
        print " ";
    print "<a href=\"$file\">$file</a><br />";
}
closedir($dh);