# $cs.File_CopyTree

> Recursively copies a directory tree from source to destination, creating destination if it doesn't exist.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-copytree/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### Description

Recursively copies a directory tree from `source` to `destination`, creating `destination` if it doesn't exist.

### Syntax

$cs.File_CopyTree(string source, string destination, bool copySubDirs = true, bool overwrite = true)

### Parameters

#### source (String)

Source folder to copy. Throws an error if it does not exist.

#### destination (String)

Destination folder to copy to. Created automatically if it doesn't exist.

#### copySubDirs (Boolean)

Also copy subfolders. Default is `$true` (full recursive copy).

#### overwrite (Boolean)

Overwrite existing files at the destination. Default is `$true`. If set to `$false`, any file that already exists at the destination is silently skipped and the rest of the copy still proceeds.

### Return value

None.

### Example

**PowerShell**

```powershell
$Source = Join-Path $global:Packageroot "Dummy"
$cs.File_CopyTree($Source, "C:\Program Files\CapaInstaller\Dummy")
```

Deploy a full configuration folder from the kit to the target machine, without overwriting any files an administrator may already have customized:

```powershell
$Source = Join-Path $global:Packageroot "kit\config"
$cs.File_CopyTree($Source, "C:\ProgramData\Contoso\App\config", $true, $false)
```

Copy only the top-level files from a folder, leaving any subfolders behind, by setting `copySubDirs=$false`:

```powershell
$Source = Join-Path $global:Packageroot "kit\templates"
$cs.File_CopyTree($Source, "C:\ProgramData\Contoso\App\templates", $false)
```

### Related functions

[$cs.File_CopyFile](/capainstaller/powerpacks/cs-file-copyfile/) [$cs.File_DelTree](/capainstaller/powerpacks/cs-file-deltree/) [$cs.File_ExistDir](/capainstaller/powerpacks/cs-file-existdir/)
