Skip to content

Latest commit

 

History

History
114 lines (78 loc) · 2.57 KB

working-with-directories.md

File metadata and controls

114 lines (78 loc) · 2.57 KB
title level
Working with directories
intermediate

Working with directories

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