php完善无沉余代码遍历文件夹

WBOY
Release: 2016-06-13 10:50:02
Original
758 people have browsed it

php完美无沉余代码遍历文件夹
参数2
0 返回目录下文件
1 返回目录下文件+目录
2 返回目录下所有 文件+空文目录(为某些2类开发,头不合适了-_-b)
3 返回目录下所有 文件
4 返回目录下所有 文件+目录
5 返回目录下所有 目录
6 返回目录下目录

什么也不说直接上代码

function get_dir( $a, $s = 0, $d = array( '.', '..' ), $f = array() ){	foreach ( scandir( $a ) as $g )	{		if ( !in_array( $g, $d ) )		{			$g = $a . '/' . $g;			if ( $s > 0 && is_dir( $g ) )			{				( $s == 1 || $s > 3 || ( $s == 2 && count( scandir( $g ) ) == 2 ) ) && $f[] = $g . '/';				$s > 1 && $s < 6 && $f = get_dir( $g, $s, $d, $f );			}			else			{				( ( $s && $s < 5 ) || ( !$s && is_file( $g ) ) ) && $f[] = $g;			};		};	};	return $f;}
Copy after login

1 楼 bupt_roy 2011-09-26  
php完善无沉余代码遍历文件夹 向大牛学习
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template