Skip to main content
Version: Fegg 5.x (next)

File::copyDirectory

Copy the contents of a directory to another directory

Description​

public void 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.

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);