码迷,mamicode.com
首页 > 其他好文 > 详细

遍历指定目录获得文件名或者文件夹名称,或者两则都要

时间:2016-11-14 07:50:21      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:使用   名称   调用   分隔符   color   direct   class   lob   []   

 1 仅获得文件名的方法
 2 function fileAction($dir)
 3 {
 4     static $files = array();  // 使用静态变量,预防递归调用的时候覆盖
 5     foreach (glob($dir.DIRECTORY_SEPARATOR.‘*‘) as $file)   
 6     // DIRECTORY_SEPARATOR :目录分隔符  win下 \  ,Linux下 /
 7     {
 8         if(!is_dir($file)){
 9             $files[] = $file;
10         }else{
11             fileAction($file);
12         }
13     }
14     return $files;
15 }
16 
17 
18 获得文件名和文件夹名的方法
19 function fetchDir($dir) 
20 {
21     static $files = array();
22     foreach(glob($dir.DIRECTORY_SEPARATOR.‘*‘) as $file) {
23         if(is_dir($file)) {
24             $files[] = $file;
25             fetchDir($file);
26         }else{
27             $files[] = $file;
28         }
29     }
30     return $files;
31 }

 

遍历指定目录获得文件名或者文件夹名称,或者两则都要

标签:使用   名称   调用   分隔符   color   direct   class   lob   []   

原文地址:http://www.cnblogs.com/online-link/p/6060548.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!