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

前端 未结 10 1927
遥遥无期
遥遥无期 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:23

    Building on Alex's tip this could help generally:

    function glob_files ($d, $e)
    {
        $files = preg_grep ("/$e\$/i", glob ("$d/*"));
        sort ($files)
        return $files;
    }
    

    where $d is the directory and $e is the extension.

提交回复
热议问题