您可以使用
glob()功能:
例01:
- <?PHP
- // read all files inside the given directory
- // limited to a specific file extension
- $files = glob("./ABC/*.txt");
- ?>
例02:
- <?PHP
- // perform actions for each file found
- foreach (glob("./ABC/*.txt") as $filename) {
- echo "$filename size " . filesize($filename) . "\n";
- }
- ?>
例03:使用RecursiveIteratorIterator
- <?PHP
- foreach(new RecursiveIteratorIterator( new RecursiveDirectoryIterator("../")) as $file) {
- if (strtolower(substr($file,-4)) == ".txt") {
- echo $file;
- }
- }
- ?>