Looking at txt files within a folder...
file2.txt
<?php
$handle = opendir('./sub');
while(false !== ($file = readdir($handle))){
if($file != '.' && $file != '..' && strtolower(pathinfo($file,PATHINFO_EXTENSION))=='txt') {
echo "$file<br />";
}
}
closedir($handle);
?>