Home

Published

- 1 min read

php get all txt files in directory

img of php get all txt files in directory

The solution for this is noted below

php get all txt files in directory

Solution

   $path = '/path/to/directory';
$files = glob($path."/*.txt");
foreach ($files as $file) {
  echo $file;
  echo '<br>';
}
/* Outputs something like: 
	/path/to/directory/someFile.txt
	/path/to/directory/someOtherFile.txt
	/path/to/directory/anotherFile.txt
*/

Try other methods by searching on the site. That is if this doesn’t work