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

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

WBOY
Release: 2016-05-30 08:44:39
Original
902 people have browsed it

本文实例讲述了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;>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template