$cs.File_ExistDir
Description
Section titled “Description”Checks whether a directory exists. Never throws — it simply returns $false if the directory is missing.
Syntax
Section titled “Syntax”$cs.File_ExistDir(string path)
Parameters
Section titled “Parameters”path (String)
Section titled “path (String)”Full path of the directory to check.
Return value
Section titled “Return value”Boolean, $true if the directory exists, $false otherwise.
Example
Section titled “Example”$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:
$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:
$sourceShare = "\\fileserver01\Deploy\Contoso"if (!$cs.File_ExistDir($sourceShare)){ Exit-PSScript -exitcode 1 -exitmessage "Source share $sourceShare is not reachable, aborting install"}Related functions
Section titled “Related functions”$cs.File_ExistFile $cs.File_CreateDirectory $cs.File_DelTree