# $cs.File_CopyFile

> Copies source to destination.

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

### Description

Copies `source` to `destination`. If `destination` is an existing folder, or ends with a path separator (`\`), the source's filename is automatically appended to it, so you can pass just a target folder. The destination's parent folder is created automatically if it doesn't exist.

### Syntax

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

### Parameters

#### source (String)

Full path to the file to copy. Throws an error if it does not exist.

#### destination (String)

Full path (or folder) to copy the file to.

#### overwrite (Boolean)

Overwrite the destination if it already exists. Default is `$true`. If set to `$false` and the destination file already exists, the copy is silently skipped — no error is raised.

### Return value

None.

### Example

**PowerShell**

```powershell
$cs.File_CopyFile("C:\Program Files\CapaInstaller\dummy.exe","C:\Windows\dummy2.exe")
```

This copies a log file to the PowerPack's log folder, making it visible in the CapaInstaller Console:

```powershell
$Destination = Join-Path $global:AppLogFolder "dism.log"
$cs.File_CopyFile("C:\Windows\Logs\DISM\dism.log", $Destination)
```

Passing a folder (or a path ending in `\`) as the destination copies the file into it under its original filename:

```powershell
$Source = Join-Path $global:Packageroot "kit\license.lic"
$cs.File_CopyFile($Source, "C:\Program Files\Contoso\App\")
```

When deploying a default configuration file, use `overwrite=$false` so an end user's existing customized copy is left untouched:

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

### Related functions

[$cs.File_CopyTree](/capainstaller/powerpacks/cs-file-copytree/) [$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/)
