0

here is my path

c:\Customers\NCR\Las Piñas

and im trying to get all the csv files.

I did the code from here (see top answer) php glob - scan in subfolders for a file

and also did a mixed recursive and glob

    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
    $html = "";

    foreach ($iterator as $folder) {
        if ($folder->isDir()) {
            $all_files = glob($folder->getRealpath() . "/*.csv");

            foreach ($all_files as $filename) {

                $html .= $filename . PHP_EOL;
            }
        }
    }
    echo $html;

and still cant read the csv inside this folder

butching
  • 192
  • 1
  • 4
  • 13
  • What do you mean with `still cant read the csv`? The posted code doesn't even try to read out the `CSV` file. Also files outside the server root won't be accessible in `PHP` – DarkBee Jan 05 '23 at 06:52
  • $all_files = glob($folder->getRealpath() . "/*.csv"); this is the code to find the csv file – butching Jan 05 '23 at 06:57

1 Answers1

0

so far this is what i came of

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));

$csvs = [];

foreach ($iterator as $folder) {

    if (!$folder->isDir()) {
        $ext = pathinfo($folder->getRealpath(), PATHINFO_EXTENSION);
        if (strtolower($ext) == 'csv') {
            $csvs[] = $folder->getRealpath();
        }
    }
}
butching
  • 192
  • 1
  • 4
  • 13