Class Filesystem
This provides convenience wrappers around common filesystem queries.
This is an internal helper class that should not be used in application code as it provides no guarantee for compatibility.
Constants
-
string
TYPE_DIR ¶'dir'
Directory type constant
Method Summary
-
copyDir() public
Copies directory with all it's contents.
-
deleteDir() public
Delete directory along with all it's contents.
-
dumpFile() public
Dump contents to file.
-
filterIterator() protected
Wrap iterator in additional filtering iterator.
-
find() public
Find files / directories (non-recursively) in given directory path.
-
findRecursive() public
Find files/ directories recursively in given directory path.
-
isStream() public
Check whether the given path is a stream path.
-
mkdir() public
Create directory.
Method Detail
copyDir() ¶ public
copyDir(string $source, string $destination): bool
Copies directory with all it's contents.
Parameters
-
string
$source Source path.
-
string
$destination Destination path.
Returns
bool
deleteDir() ¶ public
deleteDir(string $path): bool
Delete directory along with all it's contents.
Parameters
-
string
$path Directory path.
Returns
bool
Throws
Cake\Core\Exception\Exception
If path is not a directory.
dumpFile() ¶ public
dumpFile(string $filename, string $content): void
Dump contents to file.
Parameters
-
string
$filename File path.
-
string
$content Content to dump.
Returns
void
Throws
Cake\Core\Exception\Exception
When dumping fails.
filterIterator() ¶ protected
filterIterator(Iterator $iterator, mixed $filter): Iterator
Wrap iterator in additional filtering iterator.
Parameters
-
Iterator
$iterator Iterator
-
mixed
$filter Regex string or callback.
Returns
Iterator
find() ¶ public
find(string $path, mixed $filter = null, int|null $flags = null): Iterator
Find files / directories (non-recursively) in given directory path.
Parameters
-
string
$path Directory path.
-
mixed
$filter optional If string will be used as regex for filtering using
RegexIterator
, if callable will be as callback forCallbackFilterIterator
.-
int|null
$flags optional Flags for FilesystemIterator::__construct();
Returns
Iterator
findRecursive() ¶ public
findRecursive(string $path, mixed $filter = null, int|null $flags = null): Iterator
Find files/ directories recursively in given directory path.
Parameters
-
string
$path Directory path.
-
mixed
$filter optional If string will be used as regex for filtering using
RegexIterator
, if callable will be as callback forCallbackFilterIterator
. Hidden directories (starting with dot e.g. .git) are always skipped.-
int|null
$flags optional Flags for FilesystemIterator::__construct();
Returns
Iterator
isStream() ¶ public
isStream(string $path): bool
Check whether the given path is a stream path.
Parameters
-
string
$path Path.
Returns
bool
mkdir() ¶ public
mkdir(string $dir, int $mode = 0755): void
Create directory.
Parameters
-
string
$dir Directory path.
-
int
$mode optional Octal mode passed to mkdir(). Defaults to 0755.
Returns
void
Throws
Cake\Core\Exception\Exception
When directory creation fails.