note 21638 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:08:06 +0000 |
| Subject: | note 21638 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126564@lists.php.net to get a copy of this message | ||
Note Submitter: rmadriz at expressmail dot net
----
One little note about the is_dir() and is_file() functions when used with readdir().
You better use the fully qualified name when testing, otherwise you could get undesired behavior.
This is the way I'm reading the files form a directory and it is working perfectly.
function get_dir($path)
{
if ($dir = opendir($path)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($dir)))
{
if (!is_dir($path.$file))
{
//... Your Code Here
}
}
closedir($dir);
}
return // whatever you want to return, an array is very usefull
}
Hope this can help,
Rodrigo