note 21896 added to function.readdir

From: Date: Thu, 30 May 2002 19:25:55 +0000
Subject: note 21896 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-31231@lists.php.net to get a copy of this message
The entry above gave the answer to a question that I spend almost an hour looking for. But I did notice one thing that the person above did not make clear: You must join the $path and $file variables with a 'slash' ('\' on Windows, '/' on Linux). Here's my final code that I got workin correctly on Windows NT 4.0: <?php $path = "d:\path\to\your\files"; if ($handle = opendir($path)) { echo "Directory handle: $handle<br>\n"; echo "Files: \n<p>\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if(is_file($path."\\".$file)) { //Do something here. You've got a file. } else { //You've got a directory if you get here! } } closedir($handle); } ?> -- http://www.php.net/manual/en/function.readdir.php http://master.php.net/manage/user-notes.php?action=edit+21896 http://master.php.net/manage/user-notes.php?action=delete+21896 http://master.php.net/manage/user-notes.php?action=reject+21896

« previous php.notes (#31231) next »