$cs.File_ExistFile
Description
Section titled “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
Section titled “Syntax”$cs.File_ExistFile(string filepath)
Parameters
Section titled “Parameters”filepath (String)
Section titled “filepath (String)”Full path of the file to check.
Return value
Section titled “Return value”Boolean, $true if the file exists.
Example
Section titled “Example”$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:
$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:
$logFile = Join-Path $global:AppLogFolder "install.log"if ($cs.File_ExistFile($logFile)){ $cs.Job_WriteLog("Deleting leftover log file $logFile") $cs.File_DelFile($logFile)}