Re: Faster read of filenames



On 31 Oct 2006 03:22:03 -0800, in comp.lang.php "Sonnich"
<sonnich.jensen@xxxxxxxxxxxxxx>
<1162293723.742405.257780@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

| 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);
| }

glob() maybe?
foreach (glob("*.txt") as $filename)
{
echo "$filename size " . filesize($filename) . "\n";
}
---------------------------------------------------------------
jnorthau@xxxxxxxxxxxxxxxxxxxxx : Remove your pants to reply
---------------------------------------------------------------
.



Relevant Pages

  • Re: Faster read of filenames
    ... | I use the opendir and readdir to search for files... ... foreach as $filename) ...
    (comp.lang.php)
  • Re: Open a file in C
    ... > if u know the path but doan know the filename, ... > might be usefull. ... But be aware that, opendir(), and readdir() are not part of ...
    (comp.lang.c)
  • Re: Open a file in C
    ... if u know the path but doan know the filename, ... and then opendir() and readdir() functions might be usefull. ...
    (comp.lang.c)
  • Re: Compare file extensions
    ... > opendir and readdir. ... > filename extension to a variable to see if they match. ... > this with the dirent structure? ...
    (comp.unix.programmer)
  • Re: paths with space in
    ... >> end up with 'STI' as the filename and the rest of the program fails. ... > I opted for the readdir() function instead. ... having fixed this your second post shows that you also want *.tiff ... which is a little clearer I think. ...
    (perl.beginners)