# $cs.File_AppendToFile

> Appends text as a new line to the end of file. The file must already exist — this function does not create it, and throws an error if it is missing.

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

### Description

Appends `text` as a new line to the end of `file`. The file must already exist — this function does not create it, and throws an error if it is missing.

### Syntax

$cs.File_AppendToFile(string file, string text)

### Parameters

#### file (String)

Full path to the file to append the line to. The file must already exist.

#### text (String)

Text to add as a new line at the end of the file.

### Return value

None.

### Example

**PowerShell**

```powershell
$cs.File_AppendToFile("$env:windir\System32\Drivers\etc\hosts","127.0.0.1    assets.cloud.barco.com")
```

Since the file must already exist, check for it first (and create it if needed) before appending a line to an application's config file:

```powershell
$ConfigFile = "$env:ProgramData\Contoso\App\app.conf"
if (-not $cs.File_ExistFile($ConfigFile)) {
  $cs.File_CreateDirectory((Split-Path $ConfigFile))
  New-Item -Path $ConfigFile -ItemType File | Out-Null
  $cs.Job_WriteLog("Created new config file: $ConfigFile")
}
$cs.File_AppendToFile($ConfigFile, "UpdateChannel=Stable")
```

Append a marker line to the PowerPack's own log after a successful install, so it's easy to confirm which package version wrote to the machine:

```powershell
$MarkerFile = Join-Path $global:AppLogFolder "install-history.log"
if (-not $cs.File_ExistFile($MarkerFile)) {
  New-Item -Path $MarkerFile -ItemType File | Out-Null
  $cs.Job_WriteLog("Created install history file: $MarkerFile")
}
$cs.File_AppendToFile($MarkerFile, "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Installed version 3.4.1")
```

### Related functions

[$cs.File_DeleteLineInFile](/capainstaller/powerpacks/cs-file-deletelineinfile/)
