Skip to content

$cs.File_RenameFile

Renames or moves a file. Throws FileNotFoundException if source doesn’t exist. If dest already exists, overwrite controls the outcome: $true overwrites dest; $false does nothing and returns without error — no rename happens and no error is raised.

$cs.File_RenameFile(string source, string dest, bool overwrite = true)

Full path of the file to rename or move. Must exist.

Full path of the destination file.

$true to overwrite dest if it already exists; $false to silently skip the rename if dest already exists.

None.

Terminal window
$sourceFile = Join-Path $global:Packageroot "dummy.txt"
$destFile = Join-Path $global:Packageroot "moredummy.txt"
$cs.Job_WriteLog("Renaming $sourceFile to $destFile")
$cs.File_RenameFile($sourceFile, $destFile, $true)

Rename a temporary download to its final name once the download step completes:

Terminal window
$downloadedFile = Join-Path $global:Packageroot "installer.tmp"
$finalFile = Join-Path $global:Packageroot "installer.exe"
if ($cs.File_ExistFile($downloadedFile))
{
$cs.Job_WriteLog("Renaming downloaded file to $finalFile")
$cs.File_RenameFile($downloadedFile, $finalFile, $true)
}

Use overwrite=$false so a re-run of the script doesn’t clobber a config file that was already renamed into place:

Terminal window
$defaultConfig = Join-Path $global:Packageroot "config.default.xml"
$activeConfig = Join-Path $global:Packageroot "config.xml"
$cs.Job_WriteLog("Ensuring active config exists, without overwriting an existing one")
$cs.File_RenameFile($defaultConfig, $activeConfig, $false)

$cs.File_RenameDir $cs.File_CopyFile $cs.File_DelFile $cs.File_ExistFile