Try adding `&& $file->getRealPath()` to the conditional