# $cs.File_ExistFile

> Checks whether a file exists. Never throws — it returns $false both when the file is missing and when filepath is null or empty.

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

### Description

Checks whether a file exists. Never throws — it returns `$false` both when the file is missing and when `filepath` is null or empty.

### Syntax

$cs.File_ExistFile(string filepath)

### Parameters

#### filepath (String)

Full path of the file to check.

### Return value

Boolean, `$true` if the file exists.

### Example

**PowerShell**

```powershell
$exePath = Join-Path ${env:ProgramFiles(x86)} "WinSCP\WinSCP.exe"
if (!$cs.File_ExistFile($exePath))
{
  Exit-PSScript -exitcode 1 -exitmessage "WinSCP.exe not found, aborting install"
}
```

A `PreInstall` "already installed" check using a marker file dropped by a previous run:

```powershell
$markerFile = Join-Path $global:Packageroot "installed.marker"
if ($cs.File_ExistFile($markerFile))
{
  Exit-PSScript -exitcode 3330 -exitmessage "Marker file found, package already installed. Skipping."
}
```

Gate a `File_DelFile` call in `Uninstall` so it never has to handle a missing-file error:

```powershell
$logFile = Join-Path $global:AppLogFolder "install.log"
if ($cs.File_ExistFile($logFile))
{
  $cs.Job_WriteLog("Deleting leftover log file $logFile")
  $cs.File_DelFile($logFile)
}
```

### Related functions

[$cs.File_ExistDir](/capainstaller/powerpacks/cs-file-existdir/) [$cs.File_FindFile](/capainstaller/powerpacks/cs-file-findfile/) [$cs.File_DelFile](/capainstaller/powerpacks/cs-file-delfile/)
