By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

why readdir() prints . and ..

100+
P: 254
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($dirname))


Thanks
Dec 28 '07 #1
Share this Question
Share on Google+
1 Reply


code green
Expert 100+
P: 1,726
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
Expand|Select|Wrap|Line Numbers
  1. while(false!==($file=readdir($direname)))
  2. why not like this
  3. 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
Dec 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.