Directory
class Directory extends FileSystem
Class Directory
Methods
Returns whether the file path is an absolute path.
Renames a file or a directory.
Tells whether a file exists and is readable.
Change mode for an array of files or directories.
Change the owner of an array of files or directories.
No description
```php $filter = function ($current, $key, $iterator) { // \SplFileInfo $current // Skip hidden files and directories.
判断文件夹是否为空
查看一个目录中的所有文件和子目录
只获得目录结构
No description
获得目录下的文件,可选择类型、是否遍历子文件夹
获得目录下的文件,可选择类型、是否遍历子文件夹
获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹
支持层级目录的创建
复制目录内容
删除目录及里面的文件
比较文件路径
Details
in FileSystem at line 27
static bool
isAbsPath(string $path)
in FileSystem at line 49
static bool
isAbsolutePath(string $file)
Returns whether the file path is an absolute path.
in FileSystem at line 64
static string
pathFormat(string $dirName)
转换为标准的路径结构
in FileSystem at line 75
string
clearPharPath(string $path)
in FileSystem at line 94
static array|string
exists(string $file, null|string $type = null)
检查文件/夹/链接是否存在
in FileSystem at line 119
static
check(string $file, null|string|array $ext = null)
in FileSystem at line 145
static
rename(string $origin, string $target, bool $overwrite = false)
Renames a file or a directory.
in FileSystem at line 164
static bool
isReadable(string $filename)
Tells whether a file exists and is readable.
in FileSystem at line 179
static
mkdir(string|array|Traversable $dirs, int $mode = 0777)
Creates a directory recursively.
in FileSystem at line 210
static
chmod(string|array|Traversable $files, int $mode, int $umask = 00, bool $recursive = false)
Change mode for an array of files or directories.
in FileSystem at line 231
static
chown(string|array|Traversable $files, string $user, bool $recursive = false)
Change the owner of an array of files or directories.
in FileSystem at line 255
static RecursiveIteratorIterator
getIterator(string $srcDir, callable $filter)
in FileSystem at line 272
static bool
chmodDir(string $path, int $mode = 0664)
in FileSystem at line 305
static string
availableSpace(string $dir = '.')
in FileSystem at line 322
static string
countSpace(string $dir = '.')
in FileSystem at line 342
static int
pathModeInfo(string $file_path)
文件或目录权限检查函数
at line 48
static RecursiveIteratorIterator
getRecursiveIterator(string $srcDir, callable $filter)
```php $filter = function ($current, $key, $iterator) { // \SplFileInfo $current // Skip hidden files and directories.
if ($current->getFilename()[0] === '.') { return false; } if ($current->isDir()) { // Only recurse into intended subdirectories. return $current->getFilename() !== '.git'; } // Only consume files of interest. return strpos($current->getFilename(), '.php') !== false; };
// $info is instance of \SplFileInfo foreach(Directory::getRecursiveIterator($srcDir, $filter) as $info) { // $info->getFilename(); ... } ```
at line 59
static bool
isEmpty($dir)
判断文件夹是否为空
at line 87
static array
ls($path)
查看一个目录中的所有文件和子目录
at line 113
static array
getList($path, int $pid = 0, int $son = 0, array $list = [])
只获得目录结构
at line 150
static array
getDirs($path, bool $loop = false, null $parent = null, array $list = [])
at line 183
static array
simpleInfo(string $dir, string|array $ext = null, bool $recursive = false)
获得目录下的文件,可选择类型、是否遍历子文件夹
at line 224
static array
getFiles(string $path, array|string $ext = null, bool $recursive = false, null|string $parent = null, array $list = [])
获得目录下的文件,可选择类型、是否遍历子文件夹
at line 260
static array
getFilesInfo($path, array|string $ext = null, $recursive = 0, array $list)
获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹
at line 296
static bool
create($path, int|string $mode = 0775, bool $recursive = true)
支持层级目录的创建
at line 308
static bool
copy($oldDir, $newDir)
复制目录内容
at line 344
static bool
delete($path, boolean $delSelf = true)
删除目录及里面的文件
at line 367
static string
comparePath($newPath, $oldPath)
比较文件路径