Odd result from readdir()
| From: | John | Date: | Thu, 18 Jan 2024 06:08:49 +0000 |
| Subject: | Odd result from readdir() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-328356@lists.php.net to get a copy of this message | ||
I am trying to read the filenames in a directory using readdir(). There are two files and I cloned
the example in the opendir() documentation so the problem is probably not being caused by my coding:
My script running from the command line:
$indir = "/usr/shipresp/";
$outdir = "/usr/shipresp/";
if (is_dir($indir))
{
if ($dh = opendir($indir))
{
while ($filename = (readdir($dh) !== false))
{
echo "\nfound filename " . $filename;
}
}
}
?>
The result is not a list of file names:
found filename 1
found filename 1
found filename 1
found filename 1
Note the directory only has two files so I am assuming files 3 and 4 are this directory and its
parent ---> ie ./ and ../ (?).
I have the same problem with fgets($file); docs say it returns a string and all I get is
"1". I
resolved that problem by using fgetcsv($file,,"\t") since the lines are actually a csv
file anyway,
but my question is why I don't get the expected results.
Been playing with this off and on for several days now and the directory list is critical to what I
am doing.
Thanks in advance.
John
======