DirectoryIterator bug

Running WAMP on Windows XP. PHP version 5.4.3
Here’s a curious problem. I’m trying out the directory iterator object. This code is in the html body, loaded as localhost/dirtest.php

[php]<?php
$rdir=“C:\Temp”;

foreach (new DirectoryIterator($rdir) as $fileInfo) {
  if($fileInfo->isDot()) continue;
  if ($fileInfo->isDir()) echo $fileInfo->getFilename() . "</br>";
}

?>[/php]
This works fine. If I change the path to “C:\Temp\ancyc” it works ok as well. If I try this “C:\Temp\encyc” I get this -
[font=trebuchet ms]Fatal error: Uncaught exception ‘UnexpectedValueException’ with message ‘DirectoryIterator::__construct(C:\Tempencyc,C:\Tempencyc): The system cannot find the file specified. (code: 2)’ in C:\wamp\www\dirtest.php on line 10[/font]

I have tried a variety of directory names. It seems that DirectoryIterator gets confused by the letter e, lower case only, and for some reason removes the backslash. Does anyone know why this happens?

it’s probably having trouble with type. an e can trick PHP into thinking it’s a exponent, not a string.
Try casting the filename as a string.

Sorry I haven’t been back for a while, I lost all networking on the laptop I’m using as the server. Even lost localhost!! Reset it all so at least I’ve got my WAMP setup back.

I tried quotes, escaping backslash and a few other things. No luck. I was hoping to make backslashes work but replacing them by forward slashes seems to be the only solution.

Sponsor our Newsletter | Privacy Policy | Terms of Service