PDA

View Full Version : List files/directories by name?


EthanX
09-07-2003, 04:33 AM
Is there a way to list files or directories by Name?
Like by using readdir() or something?

Thanks.

Ökii
09-07-2003, 10:34 AM
the most modern way would be glob() [ > php4.3.0 ]

chdir('/home/whereever/folder');
$all_files = glob('*');

or

foreach(glob('*.htm') AS $htm_file)
{
echo $htm_file. '<br />';
}

would list all the htm files - the syntax of the search clause isn't quite regex though.

The old way would be

while (false !== ($file = readdir($handle)))
{
echo "$file\n";
}

as you surmised

EthanX
09-09-2003, 04:48 AM
Alright, but I need something for 4.2.x users.

Ökii
09-09-2003, 12:02 PM
check opendir readdir and closedir in the manual - should be enough info there.