Skip to content
Advertisement

PHP RecursiveDirectoryIterator and glob() is not working with ñ

here is my path

c:CustomersNCRLas 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

Advertisement

Answer

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();
        }
    }
}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement