Exclude hidden files from scandir

Sino picture Sino · Dec 16, 2011 · Viewed 38.4k times · Source

I am using the following code to get a list of images in a directory:

$files = scandir($imagepath);

but $files also includes hidden files. How can I exclude them?

Answer

mario picture mario · Dec 16, 2011

On Unix, you can use preg_grep to filter out filenames that start with a dot:

$files = preg_grep('/^([^.])/', scandir($imagepath));