Can PHP's glob() be made to find files in a case insensitive manner?

前端 未结 10 1933
遥遥无期
遥遥无期 2020-11-29 08:15

I want all CSV files in a directory, so I use

glob(\'my/dir/*.CSV\')

This however doesn\'t find files with a lowercase CSV extension.

10条回答
  •  情书的邮戳
    2020-11-29 08:31

    You can also filter out the files after selecting all of them

    foreach(glob('my/dir/*') as $file){
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
        if(!in_array($ext, array('csv'))){
            continue;
        }
        ... do stuff ...
    }
    

    performance wise this might not be the best option if for example you have 1 million files that are not csv in the folder.

提交回复
热议问题