Hello; I would just use scandir() if I were you. It will produce an array of file and directory names in the directory that is being scanned. Then you can use that array and loop through it to open and read files and/or directories if that is want you want to do. Best; JK > On Jan 17, 2024, at 10:08 PM, John <john.iliffe@xxxxxxxxx> wrote: > > 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 > ======