PHP: Recursively File Folder Scan
Use the function read_my_dir to scan a folder and subfolders for files and to return array of file and folder traversed. Function is a working copy of the code tested fully on Fedora5 and Window XP plateform.
function read_my_dir($dir)
{
global $tfile,$tdir;$i=0;$j=0;$myfiles;
$myfiles[][] = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file=readdir($dh)) !== false)
{
if (!is_dir($dir.”\\”.$file))
{
$tfile[$i]=$file;
$i++;
echo $dir.”\\”.$file.” – <b>File</b><br>”;
}
else
{
if (($file != “.”) && ($file != “..”))
{
$tdir[$j]=$file;
echo $dir.”\\”.$file.” – <b>Directory</b><br>”;
//$sep = “\\”;
read_my_dir($dir.”\\”.$file);
$j++;
}
}
}
closedir($dh);
}
}
}// USAGE
read_my_dir(“c:\php”);
That’s a good script……….
Thanks
Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in C:\xampp\htdocs\phpExamples\PHP\scan.php on line 12
when i given read_my_dir(“c:\xamppâ€), it showing above error, plz any suggestion
Try read_my_dir(“c:\\xamppâ€) or read_my_dir(“c:/xamppâ€) in place of read_my_dir(“c:\xamppâ€)