Here is the most effective Effective way based on this article :
function getAllFiles() { $files = array(); $dir = opendir('/ABC/'); while (($currentFile = readdir($dir)) !== false) { if (endsWith($currentFile, '.txt')) $files[] = $currentFile; } closedir($dir); return $files; } function endsWith($haystack, $needle) { return substr($haystack, -strlen($needle)) == $needle; }
just use the getAllFiles () function, and you can even change it to get the folder path and / or required extensions, it's easy.
Abdelhady
source share