Getting the names of all files in a directory with PHP Don’t bother with open/readdir and use glob instead: foreach(glob($log_directory.'/*.*') as $file) { ... }