Home >Backend Development >PHP Tutorial >PHP使用递归方式列出当前目录下所有文件的方法_php技巧

PHP使用递归方式列出当前目录下所有文件的方法_php技巧

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 20:14:431020browse

本文实例讲述了PHP使用递归方式列出当前目录下所有文件的方法。分享给大家供大家参考。具体实现方法如下:

<&#63;php<br />function filelist($pathname,$i){<br />//定义一个filelist函数<br />    $dir=opendir($pathname);<br />    while(($file=readdir($dir))!== false){<br />        $fname=$pathname."/".$file;<br />        if(is_dir($fname)&&$file!="."&&$file!=".."){<br />            for($tmp=0;$tmp<=8*$i;$tmp++)<br />                echo " ";<br />            echo '<input type="checkbox" name="Bike">';<br />            echo "is directory:".$fname."<br>";<br />            filelist($fname,$i+1);<br />        }elseif($file!="."&&$file!=".."){<br />            for($tmp=0;$tmp<=8*$i;$tmp++)<br />                echo " ";<br />            echo '<input type="checkbox" name="Bike">';<br />            echo $fname."<br>";<br />        }<br />    }<br />    chdir("..");<br />    closedir($dir);<br />}<br />filelist("/home/zhou/shell",0);<br />//列出/home/zhou/shell下的所有文件及目录。<br />&#63;>

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn