W3cubDocs

/CakePHP 4.4

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.

Namespace: Cake\Filesystem

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\CakeException
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\CakeException
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 for CallbackFilterIterator.

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 for CallbackFilterIterator. 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\CakeException
When directory creation fails.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Filesystem.Filesystem.html