while ($file = readdir(DIR)) { ... do your stuff to $file ... }