views:

121

answers:

3

I am using PHP 5's scandir($dir) function to iterate through a directory and print out an xml list of files. Only, when the directory has a single quote in the name, scandir returns no items! It doesn't return false (as it would if it failed) or generate warnings or errors - just empty. Any ideas?

$items = scandir(stripslashes($dir)); //strip slashes in case magic_quotes are on
if($items === false) die("scandir returned failure");
print_r($items)
+1  A: 

I've tested it on windows and it worked fine. Try echo $dir; to make sure it's what you expect.

Also, use ini_set() to make sure your error level is high enough:

ini_set('error_reporting', E_ALL);
Greg
Actually, I'd recommend `echo stripslashes($dir);` — make sure that *scandir* is seeing what you expect.
Ben Blank
A: 

Have you checked that the user executing the script has read permissions for the target directory?

David Grant
A: 

RoBorg was right - there were problems elsewhere in my script affecting the output, not with this particular part. Thanks, everyone!