9
9
10
10
namespace Toolkit \FsUtil ;
11
11
12
- use DirectoryIterator ;
13
- use Exception ;
14
12
use InvalidArgumentException ;
15
- use LogicException ;
16
- use RecursiveIteratorIterator ;
17
13
use Toolkit \FsUtil \Exception \FileNotFoundException ;
18
- use Toolkit \FsUtil \Exception \FileSystemException ;
19
14
use Toolkit \FsUtil \Traits \DirOperateTrait ;
20
15
use function basename ;
21
16
use function glob ;
@@ -40,17 +35,16 @@ class Directory extends FileSystem
40
35
* 只获得目录结构
41
36
*
42
37
* @param string $path
43
- * @param int $pid
44
- * @param bool $son
45
- * @param array $list
38
+ * @param int $pid
39
+ * @param bool $son
40
+ * @param array $list
46
41
*
47
42
* @return array
48
43
* @throws FileNotFoundException
49
44
*/
50
45
public static function getList (string $ path , int $ pid = 0 , bool $ son = false , array $ list = []): array
51
46
{
52
47
$ path = self ::pathFormat ($ path );
53
-
54
48
if (!is_dir ($ path )) {
55
49
throw new FileNotFoundException ("directory not exists! DIR: $ path " );
56
50
}
@@ -136,11 +130,11 @@ public static function simpleInfo(string $dir, $ext = null, bool $recursive = fa
136
130
//basename — 返回路径中的 文件名部分
137
131
$ list [] = basename ($ file );
138
132
139
- // is directory
133
+ // is directory
140
134
} else {
141
135
$ list [] = '/ ' . basename ($ file );
142
136
143
- if ($ recursive ) {
137
+ if ($ recursive && is_dir ( $ file ) ) {
144
138
/** @noinspection SlowArrayOperationsInLoopInspection */
145
139
$ list = array_merge ($ list , self ::simpleInfo ($ file , $ ext , $ recursive ));
146
140
}
@@ -156,7 +150,7 @@ public static function simpleInfo(string $dir, $ext = null, bool $recursive = fa
156
150
* @param string $path string 目标目录
157
151
* @param array|string $ext array('css','html','php') css|html|php
158
152
* @param bool $recursive 是否包含子目录
159
- * @param string $parent
153
+ * @param string $parent
160
154
* @param array $list
161
155
*
162
156
* @return array
@@ -184,7 +178,7 @@ public static function getFiles(
184
178
// 匹配文件 如果没有传入$ext 则全部遍历,传入了则按传入的类型来查找
185
179
if (is_file ($ v ) && (!$ ext || preg_match ("/\.( $ ext)$/i " , $ v ))) {
186
180
$ list [] = $ parent . $ relatePath ;
187
- } elseif ($ recursive ) {
181
+ } elseif ($ recursive && is_dir ( $ v ) ) {
188
182
$ list = self ::getFiles ($ v , $ ext , $ recursive , $ relatePath . '/ ' , $ list );
189
183
}
190
184
}
@@ -195,9 +189,9 @@ public static function getFiles(
195
189
/**
196
190
* 获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹
197
191
*
198
- * @param string $path string 目标目录
192
+ * @param string $path string 目标目录
199
193
* @param array|string $ext array('css','html','php') css|html|php
200
- * @param bool $recursive 是否包含子目录
194
+ * @param bool $recursive 是否包含子目录
201
195
* @param array $list
202
196
*
203
197
* @return array
@@ -223,8 +217,8 @@ public static function getFilesInfo(string $path, $ext = null, bool $recursive =
223
217
if (is_file ($ file ) && (!$ ext || preg_match ("/\.( $ ext)$/i " , $ file ))) {
224
218
$ list [$ id ] = File::info ($ file );
225
219
226
- // 是否遍历子目录
227
- } elseif ($ recursive ) {
220
+ // 是否遍历子目录
221
+ } elseif ($ recursive && is_dir ( $ file ) ) {
228
222
$ list = self ::getFilesInfo ($ file , $ ext , $ recursive , $ list );
229
223
}
230
224
}
@@ -235,9 +229,9 @@ public static function getFilesInfo(string $path, $ext = null, bool $recursive =
235
229
/**
236
230
* 支持层级目录的创建
237
231
*
238
- * @param string $path
239
- * @param int $mode
240
- * @param bool $recursive
232
+ * @param string $path
233
+ * @param int $mode
234
+ * @param bool $recursive
241
235
*
242
236
* @return bool
243
237
*/
@@ -287,8 +281,8 @@ public static function copy(string $oldDir, string $newDir): bool
287
281
/**
288
282
* 删除目录及里面的文件
289
283
*
290
- * @param string $path
291
- * @param boolean $delSelf 默认最后删掉自己
284
+ * @param string $path
285
+ * @param boolean $delSelf 默认最后删掉自己
292
286
*
293
287
* @return bool
294
288
*/
0 commit comments