Home >Backend Development >PHP Tutorial >PHP directory traversal viewDir function_PHP tutorial

PHP directory traversal viewDir function_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:42:351107browse

复制代码 代码如下:

/**
* Traverse the directory and find all files with a certain suffix name in the directory
**/
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:wwwtest','php');
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/320920.htmlTechArticle复制代码 代码如下: ?php /*** Traverse the directory and find all files with a certain suffix name in the directory **/ function viewDir ($directory, $ext) { if (is_dir($directory)) { $handle = open...
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