while($dir = readdir($dh) ) { if ($dir == '.' || $dir == '..') continue; // the real code }