Skip to content

$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.

$cs.File_ExistFile(string filepath)

Full path of the file to check.

Boolean, $true if the file exists.

Terminal window
$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:

Terminal window
$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:

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

$cs.File_ExistDir $cs.File_FindFile $cs.File_DelFile