class Directory extends FileSystem

Class Directory

Methods

static bool
isAbsPath(string $path)

No description

static bool
isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

static string
pathFormat(string $dirName)

转换为标准的路径结构

string
clearPharPath(string $path)

No description

static array|string
exists(string $file, null|string $type = null)

检查文件/夹/链接是否存在

static 
check(string $file, null|string|array $ext = null)

No description

static 
rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

static bool
isReadable(string $filename)

Tells whether a file exists and is readable.

static 
mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

static 
chmod(string|array|Traversable $files, int $mode, int $umask = 00, bool $recursive = false)

Change mode for an array of files or directories.

static 
chown(string|array|Traversable $files, string $user, bool $recursive = false)

Change the owner of an array of files or directories.

getIterator(string $srcDir, callable $filter)

No description

static bool
chmodDir(string $path, int $mode = 0664)

No description

static string
availableSpace(string $dir = '.')

No description

static string
countSpace(string $dir = '.')

No description

static int
pathModeInfo(string $file_path)

文件或目录权限检查函数

getRecursiveIterator(string $srcDir, callable $filter)

```php $filter = function ($current, $key, $iterator) { // \SplFileInfo $current // Skip hidden files and directories.

static bool
isEmpty($dir)

判断文件夹是否为空

static array
ls($path)

查看一个目录中的所有文件和子目录

static array
getList($path, int $pid = 0, int $son = 0, array $list = [])

只获得目录结构

static array
getDirs($path, bool $loop = false, null $parent = null, array $list = [])

No description

static array
simpleInfo(string $dir, string|array $ext = null, bool $recursive = false)

获得目录下的文件,可选择类型、是否遍历子文件夹

static array
getFiles(string $path, array|string $ext = null, bool $recursive = false, null|string $parent = null, array $list = [])

获得目录下的文件,可选择类型、是否遍历子文件夹

static array
getFilesInfo($path, array|string $ext = null, $recursive = 0, array $list)

获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹

static bool
create($path, int|string $mode = 0775, bool $recursive = true)

支持层级目录的创建

static bool
copy($oldDir, $newDir)

复制目录内容

static bool
delete($path, boolean $delSelf = true)

删除目录及里面的文件

static string
comparePath($newPath, $oldPath)

比较文件路径

Details

in FileSystem at line 27
static bool isAbsPath(string $path)

Parameters

string $path

Return Value

bool

in FileSystem at line 49
static bool isAbsolutePath(string $file)

Returns whether the file path is an absolute path.

Parameters

string $file A file path

Return Value

bool

in FileSystem at line 64
static string pathFormat(string $dirName)

转换为标准的路径结构

Parameters

string $dirName

Return Value

string

in FileSystem at line 75
string clearPharPath(string $path)

Parameters

string $path e.g phar://E:/workenv/php-dockerized/www/phplang/ugirls-social/social-uem/uem.phar/web

Return Value

string

in FileSystem at line 94
static array|string exists(string $file, null|string $type = null)

检查文件/夹/链接是否存在

Parameters

string $file 要检查的目标
null|string $type

Return Value

array|string

in FileSystem at line 119
static check(string $file, null|string|array $ext = null)

Parameters

string $file
null|string|array $ext eg: 'jpg|gif'

Exceptions

FileNotFoundException
InvalidArgumentException

in FileSystem at line 145
static rename(string $origin, string $target, bool $overwrite = false)

Renames a file or a directory.

Parameters

string $origin The origin filename or directory
string $target The new filename or directory
bool $overwrite Whether to overwrite the target if it already exists

Exceptions

IOException When target file or directory already exists
IOException When origin cannot be renamed

in FileSystem at line 164
static bool isReadable(string $filename)

Tells whether a file exists and is readable.

Parameters

string $filename Path to the file

Return Value

bool

Exceptions

IOException When windows path is longer than 258 characters

in FileSystem at line 179
static mkdir(string|array|Traversable $dirs, int $mode = 0777)

Creates a directory recursively.

Parameters

string|array|Traversable $dirs The directory path
int $mode The directory mode

Exceptions

IOException On any directory creation failure

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.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change mode
int $mode The new mode (octal)
int $umask The mode mask (octal)
bool $recursive Whether change the mod recursively or not

Exceptions

IOException When the change fail

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.

Parameters

string|array|Traversable $files A filename, an array of files, or a \Traversable instance to change owner
string $user The new owner user name
bool $recursive Whether change the owner recursively or not

Exceptions

IOException When the change fail

in FileSystem at line 255
static RecursiveIteratorIterator getIterator(string $srcDir, callable $filter)

Parameters

string $srcDir
callable $filter

Return Value

RecursiveIteratorIterator

in FileSystem at line 272
static bool chmodDir(string $path, int $mode = 0664)

Parameters

string $path
int $mode

Return Value

bool

in FileSystem at line 305
static string availableSpace(string $dir = '.')

Parameters

string $dir

Return Value

string

in FileSystem at line 322
static string countSpace(string $dir = '.')

Parameters

string $dir

Return Value

string

in FileSystem at line 342
static int pathModeInfo(string $file_path)

文件或目录权限检查函数

Parameters

string $file_path 文件路径

Return Value

int 返回值的取值范围为{0 <= x <= 15},每个值表示的含义可由四位二进制数组合推出。 返回值在二进制计数法中,四位由高到低分别代表 可执行rename()函数权限 |可对文件追加内容权限 |可写入文件权限|可读取文件权限。

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(); ... } ```

Parameters

string $srcDir
callable $filter

Return Value

RecursiveIteratorIterator

Exceptions

LogicException

at line 59
static bool isEmpty($dir)

判断文件夹是否为空

Parameters

$dir

Return Value

bool

Exceptions

FileSystemException

at line 87
static array ls($path)

查看一个目录中的所有文件和子目录

Parameters

$path

Return Value

array

Exceptions

FileNotFoundException

at line 113
static array getList($path, int $pid = 0, int $son = 0, array $list = [])

只获得目录结构

Parameters

$path
int $pid
int $son
array $list

Return Value

array

Exceptions

FileNotFoundException

at line 150
static array getDirs($path, bool $loop = false, null $parent = null, array $list = [])

Parameters

$path
bool $loop
null $parent
array $list

Return Value

array

Exceptions

FileNotFoundException

at line 183
static array simpleInfo(string $dir, string|array $ext = null, bool $recursive = false)

获得目录下的文件,可选择类型、是否遍历子文件夹

Parameters

string $dir string 目标目录
string|array $ext array('css','html','php') css|html|php
bool $recursive int|bool 是否包含子目录

Return Value

array

Exceptions

FileNotFoundException

at line 224
static array getFiles(string $path, array|string $ext = null, bool $recursive = false, null|string $parent = null, array $list = [])

获得目录下的文件,可选择类型、是否遍历子文件夹

Parameters

string $path string 目标目录
array|string $ext array('css','html','php') css|html|php
bool $recursive 是否包含子目录
null|string $parent
array $list

Return Value

array

Exceptions

FileNotFoundException

at line 260
static array getFilesInfo($path, array|string $ext = null, $recursive = 0, array $list)

获得目录下的文件以及详细信息,可选择类型、是否遍历子文件夹

Parameters

$path string 目标目录
array|string $ext array('css','html','php') css|html|php
$recursive int|bool 是否包含子目录
array $list

Return Value

array

Exceptions

InvalidArgumentException
FileNotFoundException

at line 296
static bool create($path, int|string $mode = 0775, bool $recursive = true)

支持层级目录的创建

Parameters

$path
int|string $mode
bool $recursive

Return Value

bool

at line 308
static bool copy($oldDir, $newDir)

复制目录内容

Parameters

$oldDir
$newDir

Return Value

bool

Exceptions

FileNotFoundException

at line 344
static bool delete($path, boolean $delSelf = true)

删除目录及里面的文件

Parameters

$path
boolean $delSelf 默认最后删掉自己

Return Value

bool

at line 367
static string comparePath($newPath, $oldPath)

比较文件路径

Parameters

$newPath
$oldPath

Return Value

string