99
1010namespace Toolkit \FsUtil ;
1111
12- use DirectoryIterator ;
13- use Exception ;
1412use InvalidArgumentException ;
15- use LogicException ;
16- use RecursiveIteratorIterator ;
1713use Toolkit \FsUtil \Exception \FileNotFoundException ;
18- use Toolkit \FsUtil \Exception \FileSystemException ;
1914use Toolkit \FsUtil \Traits \DirOperateTrait ;
2015use function basename ;
2116use function glob ;
@@ -40,17 +35,16 @@ class Directory extends FileSystem
4035 * 只获得目录结构
4136 *
4237 * @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
4641 *
4742 * @return array
4843 * @throws FileNotFoundException
4944 */
5045 public static function getList (string $ path , int $ pid = 0 , bool $ son = false , array $ list = []): array
5146 {
5247 $ path = self ::pathFormat ($ path );
53-
5448 if (!is_dir ($ path )) {
5549 throw new FileNotFoundException ("directory not exists! DIR: $ path " );
5650 }
@@ -136,11 +130,11 @@ public static function simpleInfo(string $dir, $ext = null, bool $recursive = fa
136130 //basename — 返回路径中的 文件名部分
137131 $ list [] = basename ($ file );
138132
139- // is directory
133+ // is directory
140134 } else {
141135 $ list [] = '/ ' . basename ($ file );
142136
143- if ($ recursive ) {
137+ if ($ recursive && is_dir ( $ file ) ) {
144138 /** @noinspection SlowArrayOperationsInLoopInspection */
145139 $ list = array_merge ($ list , self ::simpleInfo ($ file , $ ext , $ recursive ));
146140 }
@@ -156,7 +150,7 @@ public static function simpleInfo(string $dir, $ext = null, bool $recursive = fa
156150 * @param string $path string 目标目录
157151 * @param array|string $ext array('css','html','php') css|html|php
158152 * @param bool $recursive 是否包含子目录
159- * @param string $parent
153+ * @param string $parent
160154 * @param array $list
161155 *
162156 * @return array
@@ -184,7 +178,7 @@ public static function getFiles(
184178 // 匹配文件 如果没有传入$ext 则全部遍历,传入了则按传入的类型来查找
185179 if (is_file ($ v ) && (!$ ext || preg_match ("/\.( $ ext)$/i " , $ v ))) {
186180 $ list [] = $ parent . $ relatePath ;
187- } elseif ($ recursive ) {
181+ } elseif ($ recursive && is_dir ( $ v ) ) {
188182 $ list = self ::getFiles ($ v , $ ext , $ recursive , $ relatePath . '/ ' , $ list );
189183 }
190184 }
@@ -195,9 +189,9 @@ public static function getFiles(
195189 /**
196190 * 获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹
197191 *
198- * @param string $path string 目标目录
192+ * @param string $path string 目标目录
199193 * @param array|string $ext array('css','html','php') css|html|php
200- * @param bool $recursive 是否包含子目录
194+ * @param bool $recursive 是否包含子目录
201195 * @param array $list
202196 *
203197 * @return array
@@ -223,8 +217,8 @@ public static function getFilesInfo(string $path, $ext = null, bool $recursive =
223217 if (is_file ($ file ) && (!$ ext || preg_match ("/\.( $ ext)$/i " , $ file ))) {
224218 $ list [$ id ] = File::info ($ file );
225219
226- // 是否遍历子目录
227- } elseif ($ recursive ) {
220+ // 是否遍历子目录
221+ } elseif ($ recursive && is_dir ( $ file ) ) {
228222 $ list = self ::getFilesInfo ($ file , $ ext , $ recursive , $ list );
229223 }
230224 }
@@ -235,9 +229,9 @@ public static function getFilesInfo(string $path, $ext = null, bool $recursive =
235229 /**
236230 * 支持层级目录的创建
237231 *
238- * @param string $path
239- * @param int $mode
240- * @param bool $recursive
232+ * @param string $path
233+ * @param int $mode
234+ * @param bool $recursive
241235 *
242236 * @return bool
243237 */
@@ -287,8 +281,8 @@ public static function copy(string $oldDir, string $newDir): bool
287281 /**
288282 * 删除目录及里面的文件
289283 *
290- * @param string $path
291- * @param boolean $delSelf 默认最后删掉自己
284+ * @param string $path
285+ * @param boolean $delSelf 默认最后删掉自己
292286 *
293287 * @return bool
294288 */
0 commit comments