# $cs.File_ExistDir

> Checks whether a directory exists. Never throws — it simply returns $false if the directory is missing.

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

### Description

Checks whether a directory exists. Never throws — it simply returns `$false` if the directory is missing.

### Syntax

$cs.File_ExistDir(string path)

### Parameters

#### path (String)

Full path of the directory to check.

### Return value

Boolean, `$true` if the directory exists, `$false` otherwise.

### Example

**PowerShell**

```powershell
$installFolder = Join-Path ${env:ProgramFiles(x86)} "WinSCP"
if ($cs.File_ExistDir($installFolder))
{
  $cs.Job_WriteLog("WinSCP folder found, skipping creation")
}
else
{
  $cs.File_CreateDirectory($installFolder)
}
```

In `Uninstall`, skip a cleanup step entirely if the data folder was never created:

```powershell
$dataFolder = Join-Path $env:ProgramData "Contoso\AppData"
if ($cs.File_ExistDir($dataFolder))
{
  $cs.Job_WriteLog("Removing leftover data folder $dataFolder")
  $cs.File_DelTree($dataFolder)
}
else
{
  $cs.Job_WriteLog("No data folder present, nothing to clean up")
}
```

A `PreInstall` check that a required source share is reachable before continuing:

```powershell
$sourceShare = "\\fileserver01\Deploy\Contoso"
if (!$cs.File_ExistDir($sourceShare))
{
  Exit-PSScript -exitcode 1 -exitmessage "Source share $sourceShare is not reachable, aborting install"
}
```

### Related functions

[$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/) [$cs.File_CreateDirectory](/capainstaller/powerpacks/cs-file-createdirectory/) [$cs.File_DelTree](/capainstaller/powerpacks/cs-file-deltree/)
