Finding all file paths using php's iterators

I am trying to find all file paths using the following code. The problem I am facing is that some files - it looks like only files with very long names, as far as I can tell - are not being detected. I am on Windows 7 64bit.

Here is my code:



$folder = 'tmp_folder';

$directory = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::LEAVES_ONLY);

$imagePaths = array();

// add each path found to the array
foreach ($iterator as $file)
{
	
	$filePath = realpath($file);
	$imagePaths [] = $filePath ;
}


This code appeared to work fine until I tried a file with a very long file name. (The file contains no illegal characters.) The file has a name of 193 characters. Including the path, the path to the file is 263 characters. I know windows has a ~255 character limit on file names, but is this for paths as well? And is there anyway around this? I can access the file fine in Explorer, but it’s strange PHP this code doesn’t detect it. I did some looking around and it seems that windows is supposed to have a 255 character path limit - not just file name limit - but this doesn’t seem to be a problem here as I can access and navigate to the file.

What’s going on here? Can I get around this? Do I need to resort to a self-made iterator? And if I do, any thoughts on how to build them?