# echo filenames

in windows want to interate through all the files in  a directory
that match file extension .php
and echo file name
LVL 1
###### Who is Participating?

x

Senior Web DeveloperCommented:
Try something like this;

<?php
$dir_path = '\\path\\to\\directory'; if ($handle = opendir($dir_path)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && preg_match('/\.php$/im', $entry)) { echo "$entry\n";
}
}
closedir($handle); } ?>  Have not tested this, but hope it helps. ~AB 0 Commented: <?php$dir = "*";
foreach(glob($dir) as$file)
{
if(pathinfo($file, PATHINFO_EXTENSION)=="php"){ echo$file ."<br>";
}
}
?>

0

Commented:
Have a look at scandir() and glob().  Both will return an array. You can use an iterator like foreach() to access each element of the array.
0

Commented:
Just to add, if you want a sub directory then amend
$dir = "*"; to$dir = "mydir/*";
0

Author Commented:
these loop through the files

thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.