zoukankan      html  css  js  c++  java
  • 获取指定目录下的所有文件名和路径(包括子目录)

    简介:这是获取指定目录下的所有文件名和路径(包括子目录)的详细页面,介绍了和php,php, 获取目录文件, 子目录文件 获取指定目录下的所有文件名和路径(包括子目录)有关的知识、技巧、经验,和一些php源码等。

    class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=344670' scrolling='no'>

    获取指定目录下的所有文件名和路径,同时也包括子目录在内的所有文件

    	/**
    	*   获取指定目录下的文件列表
    	*	string $path 指定的目录,默认为当前目录
    	*	string $exten 文件扩展名带前面的点(.txt),默认显示全部文件
    	*	string $ifchild 是否显示子目录文件列表,默认不显示
    	*/
    	function openpath($path=".", $exten = '*' ,$ifchild = false){
    		$array = array();
    		static $file_array=array(); //存放文件名数组
    		static $path_array=array(); //存放路径数组(不包括文件名)
    		$path = preg_replace('/(.*)([^\/])$/', '$1$2/', $path);
    		if(is_dir($path)){  //检查文件目录是否存在
    			$H = @ opendir($path);
    			while(false !== ($_file=readdir($H))){
    				//检索目录
    				if(is_dir($path.$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){
    					if($ifchild){
    						openpath($path.$_file, $exten ,$ifchild);
    					}
    				//检索文件
    				}elseif(is_file($path.$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
    					//$_file = auto_charset($_file,'utf-8','gbk');
    					if($exten == '*'){
    						array_push($file_array, $_file);
    						array_push($path_array, $path);
    					} else {
    						if(preg_match('/(.*)'.$exten.'/', '/'.$_file.'/')){
    							array_push($file_array, $_file);
    							array_push($path_array, $path);
    						}
    					}
    				}
    			}
    			closedir($H);
    		}
    		$array['name'] = $file_array;
    		$array['path'] = $path_array;
    		return $array;
    	}	

    爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

    http://biancheng.dnbcw.info/php/344670.html pageNo:4
  • 相关阅读:
    给a标签加样式的写法
    IE6、IE7下不支持overflowy:hidden;
    fontfamily:微软雅黑
    文字加下划线
    IE8下按钮与右边的距离比IE7和IE6的多了一倍
    在button(div)里设置背景图后,在IE6下背景图的高度被撑开了
    li中包含span,在IE6、IE7下会有3pxbug
    事件冒泡
    [LeetCode] Insert Interval 解题报告
    [LeetCode] Generate Parentheses 解题报告
  • 原文地址:https://www.cnblogs.com/ooooo/p/2240624.html
Copyright © 2011-2022 走看看