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
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
You can exclude files and folders which starting "." by using following code
$ignoreList = array('cgi-bin', '.', '..', '._');
if ($directory = opendir(APPPATH . 'controllers/user')) {
while (false !== ($filename = readdir($directory))) {
if (!in_array($filename, $ignoreList) and substr($filename, 0, 1) != '.') {
echo $filename."<br>";
}
}
}
If you just want to exclude files starting with a dot, ".", you can do something like this:
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.