Home > Backend Development > PHP Tutorial > PHP recursive traversal traverses all files and sub-files in a folder_PHP tutorial

PHP recursive traversal traverses all files and sub-files in a folder_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:44:41
Original
846 people have browsed it

Now let me recommend to you an example code of php recursive traversal to traverse all files and sub-files in a folder written by a netizen. I hope it will be helpful to all my friends.


Write a function that can traverse all files and subfolders in a folder.

The code is as follows
 代码如下 复制代码

$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);

Copy code
$dirs='e:/pdf';

function FileShow($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); http://www.bkjia.com/PHPjc/633066.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633066.htmlTechArticleLet me recommend an example of php recursive traversal written by a netizen to traverse all files and sub-files in a folder. Code, I hope it will be helpful to all my friends. Write a function that can...
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template