# $cs.File_RenameFile

> Renames or moves a file. Throws FileNotFoundException if source doesn't exist.

Source: https://docs.capaone.com/capainstaller/powerpacks/cs-file-renamefile/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

### 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

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

### Parameters

#### source (String)

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

#### dest (String)

Full path of the destination file.

#### overwrite (Boolean)

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

### Return value

None.

### Example

**PowerShell**

```powershell
$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:

```powershell
$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:

```powershell
$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

[$cs.File_RenameDir](/capainstaller/powerpacks/cs-file-renamedir/) [$cs.File_CopyFile](/capainstaller/powerpacks/cs-file-copyfile/) [$cs.File_DelFile](/capainstaller/powerpacks/cs-file-delfile/) [$cs.File_ExistFile](/capainstaller/powerpacks/cs-file-existfile/)
