prova così....
while (false !== ($entry = $d->read())) {
if (is_dir($d->path."/".$entry)){
.............

ciao