php获取目录下所有文件路径(递归)
程序员文章站
2022-05-03 19:41:38
php获取目录下所有文件路径(递归)
目录如下:
D:\adir>tree /A /F
D:.
| afile1.rar
| afile2.txt
|...
php获取目录下所有文件路径(递归)
目录如下:
D:\adir>tree /A /F D:. | afile1.rar | afile2.txt | afile3.BMP | +---bdir | bfile1.rar | bfile2.txt | bfile3.BMP | \---cdir | cfile1.rar | cfile2.txt | cfile3.BMP | \---ddir | dfile1.rar | dfile2.txt | dfile3.BMP | \---edir efile1.rar efile2.txt efile3.BMP
具体代码:
read()) { if((is_dir("$directory/$file")) AND ($file != ".") AND ($file != "..")) { tree($arr_file, "$directory/$file", "$dir_name/$file"); } else if(($file != ".") AND ($file != "..")) { $arr_file[] = "$dir_name/$file"; } } $mydir->close(); } //开始运行 $arr_file = array(); tree($arr_file, "D:/adir"); print_r($arr_file);
运行结果:
Array ( [0] => /afile1.rar [1] => /afile2.txt [2] => /afile3.BMP [3] => /bdir/bfile1.rar [4] => /bdir/bfile2.txt [5] => /bdir/bfile3.BMP [6] => /cdir/cfile1.rar [7] => /cdir/cfile2.txt [8] => /cdir/cfile3.BMP [9] => /cdir/ddir/dfile1.rar [10] => /cdir/ddir/dfile2.txt [11] => /cdir/ddir/dfile3.BMP [12] => /cdir/ddir/edir/efile1.rar [13] => /cdir/ddir/edir/efile2.txt [14] => /cdir/ddir/edir/efile3.BMP )
注意:这里没有将中文文件名进行转码。
下一篇: SQL语句执行顺序、步骤讲解