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