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 summary

  • string
    TYPE_DIR
    'dir'

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)

Copies directory with all it's contents.

Parameters

string $source

Source path.

string $destination

Destination path.

Returns

bool

deleteDir() public

deleteDir(string $path)

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)

Dump contents to file.

Parameters

string $filename

File path.

string $content

Content to dump.

Throws

Cake\Core\Exception\Exception
When dumping fails.

filterIterator() protected

filterIterator(\Iterator $iterator, mixed $filter)

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, ?int $flags)

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, ?int $flags)

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)

Check whether the given path is a stream path.

Parameters

string $path

Path.

Returns

bool

mkdir() public

mkdir(string $dir, int $mode)

Create directory.

Parameters

string $dir

Directory path.

int $mode optional

Octal mode passed to mkdir(). Defaults to 0755.

Throws

Cake\Core\Exception\Exception
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.0/class-Cake.Filesystem.Filesystem.html