How do I exclude hidden folders and files from readdir?

kcssm picture kcssm · Feb 11, 2011 · Viewed 7.4k times · Source

Is it possible to exclude hidden files and folders from the readdir() function? I have a directory where there are many folders and some hidden folders. I want to read all folders except the hidden ones.

Thanks for any help.

Kcssm

Answer

arnorhs picture arnorhs · Feb 11, 2011

If you just want to exclude files starting with a dot, ".", you can do something like this:

$files = readdir('/path/to/folder');
$files = array_filter($files, create_function('$a','return ($a[0]!=".");'));

This will only return files that don't start with dot "."

On windows, hidden files work differently, I don't know how to find those out.