Faster read of filenames



Hi all

I use the opendir and readdir to search for files... but they read in
all files, so sometimes I get several hundreds.
If there is a way to give a wildcard, it might be a lot faster.
Since I do this search 100+ times at certain times, this is the thing
which slows me down.
Disableing this part speeds my code up by 90%.

Any ideas?

Sonnich


if($handle = opendir($sSearchPath))
{
while (false !== ($file = readdir($handle)))
{
$file2 = strtoupper($file);
if( (strpos($file2, $code)!==False) && (strpos($file2,
".PDF")!==False))
{
$files[] = $file;
$paths[] = $sSearchPath;
}
}
closedir($handle);
}

.



Relevant Pages

  • Re: opendir function.
    ... on betterwith the successive execution of the script ... readdir() in list context should be slightly faster than in scalar ... If your overall algorithm calls opendir() multiple times to descend ... closedir $dh; ...
    (comp.lang.perl.misc)
  • Re: Removing all files inside a directory in Linux using an API call from a C Code
    ... Aditya wrote: ... defeats the purpose. ... That's what readdir() is for. ... Like I said, open the directory file with opendir(), read it's contents ...
    (comp.unix.programmer)
  • Re: opendir and readdir vs glob iteration
    ... > Under what circumstances (and in what manner) would it be advantageous ... opendir and readdir are somewhat more memory efficient, ... Xho ...
    (comp.lang.perl.misc)
  • Re: Directory reading
    ... As proposed by others, the functions opendir(), readdir() and ... closedir() are the way to read a directory under Linux/UNIX/Bsd. ...
    (comp.lang.c)
  • Re: String searching in a FILE*
    ... opendir(), readdir(), and closedir() than to use popen, fread(), and pclose. ...
    (comp.lang.c)