Edit on GitHub
Jump to docs navigation

Extending / Filesystem Layer / Working with directories

Note: You are currently reading the documentation for Bolt 3.3. Looking for the documentation for Bolt 3.5 instead?

Each directory in the filesystem is an instance of an \Bolt\Filesystem\Handler\DirectoryInterface object.

Get a directory object

    /** @var \Bolt\Filesystem\Handler\DirectoryInterface $dirObj */
    $dirObj = $filesystem->getDir($path);
Variable Type Description
$path string The path to the directory

Checking if a directory exists

    /** @var bool $exists */
    $exists = $dirObj->exists($path);
Variable Type Description
$path string The path to the directory

Copy Directories

Copies a directory and its contents to another.

    $filesystem->copyDir($originDir, $targetDir, $override = null);

Where:

Variable Type Description
$originDir string The origin directory
$targetDir string The target directory
override bool/null Whether to override an existing file
true = always override the target
false = never override the target
null = only override the target if the source is newer

Mirror Directories

Mirrors a directory to another.

Note: By default, this will delete files in target if they are not in source.

    $filesystem->mirror($originDir, $targetDir, $config = []);

Where:

Variable Type Description
$originDir string The origin directory
$targetDir string The target directory
$config array Array of option parameter/keys

Key/value pairs that make up $config

Name Type Description
delete bool/null Whether to delete files that are not in the source
override bool/null Whether to override an existing file
true = always override the target
false = never override the target
null = only override the target if the source is newer

Create Directories

Create a directory.

    $filesystem->createDir($dirname, $config = []);

Where:

Variable Type Description
$dirname string The target directory
$config array Optional configuration array

Delete Directories

Delete a directory.

    $filesystem->deleteDir($dirname);

Where:

Variable Type Description
$dirname string The target directory
Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.