why readdir() prints . and ..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshrasm
    Contributor
    • Nov 2007
    • 254

    #1

    why readdir() prints . and ..

    Hi,

    When I used readdir() function and echo the file name it prints . and .. as well.Whereas there is no such file with name . or.. , so why it is printing it. What does it mean? And one more thing why we should loop over directory like

    while(false!==( $file=readdir($ direname)))

    why not like this

    while($filename =readdir($dirna me))


    Thanks
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    When I used readdir() function and echo the file name it prints . and .. as well. Whereas there is no such file with name . or.. , so why it is printing it. What does it mean?
    Whoops I've forgotten.
    Wait, I think they are sub-directories in the directory.
    And one more thing why we should loop over directory like
    Code:
    while(false!==($file=readdir($direname)))
    why not like this
    while($filename=readdir($dirname))
    This is the manual explanation
    Please note the fashion in which readdir()'s return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0").
    Makes you wanna cry doesn't it

    Comment

    Working...