Skip to main content
Version: Fegg 5.x

File::copyDirectory

Copy the contents of a directory to another directory

Description​

public bool File::copyDirectory( string $fromDirectory, string $toDirectory, [ boolean $recursiveCallFlag = false ] )

Copies the files under $fromDirectory to $toDirectory. The destination directory must already exist. When $recursiveCallFlag is true, subdirectories are created in the destination and copied as well. Symbolic links are skipped.

Returns false when one of the directories does not exist or something could not be copied.

Arguments​

NameData typeDefaultRemarks
$fromDirectorystringSource directory
$toDirectorystringDestination directory (must exist)
$recursiveCallFlagbooleanfalsetrue: also copy subdirectories recursively

Example​

Controller
use Fegg\Tool\File;

$file = new File();

// Only the files directly under path/to/foo
$file->copyDirectory('path/to/foo', 'path/to/bar');

// Including subdirectories
$file->copyDirectory('path/to/foo', 'path/to/bar', true);