note 21638 added to function.readdir

From: Date: Tue, 21 May 2002 20:54:47 +0000
Subject: note 21638 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-30866@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/function.readdir.php http://master.php.net/manage/user-notes.php?action=edit+21638 http://master.php.net/manage/user-notes.php?action=delete+21638 http://master.php.net/manage/user-notes.php?action=reject+21638

« previous php.notes (#30866) next »