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...
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