note 21896 deleted from function.readdir by philip

From: Date: Fri, 08 Nov 2002 01:56:26 +0000
Subject: note 21896 deleted from function.readdir by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39117@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); } ?>

« previous php.notes (#39117) next »