Q:

PHP DirectoryIterator and .DS_Store File

I have a local XAMP install on my Mac. I have this code:
foreach (new DirectoryIterator('test') as $fileInfo) {
    if ($fileInfo->isDot() && $fileInfo->getBasename() !== '.DS_Store') {
        continue;
    }

    $xmlFile = "test/" . $fileInfo->getFilename() . "/content.xml";

    if (file_exists($xmlFile)) {
        $xml = simplexml_load_file($xmlFile);
        foreach ($xml->infos as $infos) {
            echo "<li><a href='#tab_3' data-toggle='tab'>$infos->bezeichnung</a></li>";
        }
    }
}

The problem is that I get an error that says that the file .DS_Store cannot be opened. I thought my code filtered out the .DS_Store directory. It's clear that this file cannot be opened. It is a mac specific folder.

A:

Your filter is saying "if it is a dot file and it is not .DS_Store, skip it" which is the opposite of what I believe you want. Try this:
if ($fileInfo->isDot() || $fileInfo->getBasename() === '.DS_Store') {
    continue;
}

Which says "if it is a dot file (. or ..) or it is .DS_Store, skip it."

