catchAdmin/extend/catcher/library/FileSystem.php
2020-07-02 13:19:23 +08:00

78 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
namespace catcher\library;
class FileSystem
{
/**
* 获取目录下所有文件
*
* @time 2020年07月02日
* @param $path
* @return array
*/
public function allFiles($path)
{
$files = $this->files($path);
$dirs = $this->dirs($path);
foreach ($dirs as $dir) {
$files = array_merge($files, $this->allFiles($dir));
}
return $files;
}
/**
* 获取文件夹下的文件
*
* @time 2020年07月02日
* @param $path
* @return array
*/
public function files($path)
{
$files = [];
$fileSystemIterator = new \FilesystemIterator($path);
foreach ($fileSystemIterator as $fileSystem) {
if (!$fileSystem->isDir()) {
$files[] = $fileSystem->getPathName();
}
}
return $files;
}
/**
* 获取文件夹
*
* @time 2020年07月02日
* @param $path
* @return array
*/
public function dirs($path)
{
$dirs = [];
$fileSystemIterator = new \FilesystemIterator($path);
foreach ($fileSystemIterator as $fileSystem) {
if ($fileSystem->isDir()) {
$dirs[] = $fileSystem->getPathname();
}
}
return $dirs;
}
}