Home > php教程 > php手册 > php递归遍历之遍历文件夹下的所有文件和子文件

php递归遍历之遍历文件夹下的所有文件和子文件

WBOY
Release: 2016-06-13 09:48:06
Original
1322 people have browsed it

下面我来给大家推荐一个网友写的php递归遍历之遍历文件夹下的所有文件和子文件实例代码,希望对各位朋友有所帮助。


写一个函数,能够遍历一个文件夹下的所有文件和子文件夹。

 代码如下 复制代码

$dirs='e:/pdf'; 

function FileShow($dirs) { 

    $dir=opendir($dirs); 

    while ($f=readdir($dir)) { 

    if($f != '.' && $f != '..'){ 

    $file=$dirs.'/'.$f; 

    if(is_file($file)){ 

        echo 'FileName:'.$file.'
'; 

        //echo 'FileName:'.iconv('gb2312','utf-8',$file).'
'; 

    }else{ 

        FileShow($file); 

        } 

    } 

    } 

FileShow($dirs);

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template