Home >Backend Development >PHP Tutorial >php遍历目录viewDir函数_php技巧

php遍历目录viewDir函数_php技巧

WBOY
WBOYOriginal
2016-05-17 09:29:04925browse
复制代码 代码如下:

/**
* 遍历目录,找出目录下某个后缀名的所有文件
* */
function viewDir ($directory, $ext) {
if (is_dir($directory)) {
$handle = opendir($directory);
while ($file = readdir($handle)){
$subdir = $directory . '/' .$file;
if ($file != '.' && $file !='..' && is_dir($subdir)){
viewDir($subdir,$ext);
} else if( $file != '.' && $file != '..') {
$fileInfo = pathinfo($subdir);
$fileExt = $fileInfo['extension'];
if ($fileExt == $ext){
echo $directory.'/'.$file.'
';
}
}
}
closedir($handle);
}
}
viewDir('E:\www\test','php');
?>
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