$cs.File_RenameFile
Description
Section titled “Description”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.
Syntax
Section titled “Syntax”$cs.File_RenameFile(string source, string dest, bool overwrite = true)
Parameters
Section titled “Parameters”source (String)
Section titled “source (String)”Full path of the file to rename or move. Must exist.
dest (String)
Section titled “dest (String)”Full path of the destination file.
overwrite (Boolean)
Section titled “overwrite (Boolean)”$true to overwrite dest if it already exists; $false to silently skip the rename if dest already exists.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$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:
$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:
$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)Related functions
Section titled “Related functions”$cs.File_RenameDir $cs.File_CopyFile $cs.File_DelFile $cs.File_ExistFile