Home >php教程 >php手册 >遍历某个目录以及其目录的文件

遍历某个目录以及其目录的文件

WBOY
WBOYOriginal
2016-06-06 19:33:23960browse

遍历某个目录以及其目录的文件,仅用于linux 无 ?phpclass path_list { function dir_list($dir) { if (is_dir ( $dir ) === false) { exit ( '目录路径不存在!' ); } $list = scandir ( $dir ); foreach ( $list as $key = $file ) { if (($file != '.') ($f

遍历某个目录以及其目录的文件,仅用于linux
<?php

class path_list {

 function dir_list($dir) {

 if (is_dir ( $dir ) === false) {

 exit ( '目录路径不存在!' );

 }

 

 $list = scandir ( $dir );

 

 foreach ( $list as $key => $file ) {

 if (($file != '.') && ($file != '..')) {

 if (is_dir ( $dir . '/' . $file )) {

 $row [$file] = $this->dir_list ( $dir . '/' . $file );

 } else {

 $row [$file] = $file;

 }

 }

 }

 

 return $row;

 }

}
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