It works for the most part, and returns 10,000 odd items which is correct.
But it leaves a blank array item where the file or directory name contains an ampersand &
When using the function below, is there any way to escape these characters when this function is running so that I can display them in the array??
Any ideas?
I'm using the globr() function by 'sthomas at townnews dot com' on the glob manual page...
Code: Select all
/**
* Recursive version of glob
*
* @return array containing all pattern-matched files.
*
* @param string $sDir Directory to start with.
* @param string $sPattern Pattern to glob for.
* @param int $nFlags Flags sent to glob.
*/
function globr($sDir, $sPattern, $nFlags = NULL)
{
$sDir = escapeshellcmd($sDir);
// Get the list of all matching files currently in the
// directory.
$aFiles = glob("$sDir/$sPattern", $nFlags);
// Then get a list of all directories in this directory, and
// run ourselves on the resulting array. This is the
// recursion step, which will not execute if there are no
// directories.
foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir)
{
$aSubFiles = globr($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}
// The array we return contains the files we found, and the
// files all of our children found.
return $aFiles;
}
// CODE THAT I'VE ADDED
$filelist = globr("I:/", "*");
echo ("<pre>");
print_r ($filelist);
echo ("</pre>");