# $cs.File_RenameDir

> Renames or moves a directory. Throws DirectoryNotFoundException if source doesn't exist.

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

### Description

Renames or moves a directory. Throws `DirectoryNotFoundException` if `source` doesn't exist. If `dest` does not already exist, this is a plain fast move. If `dest` already exists, the behavior depends on `overwrite`: `$true` merges by copying the contents of `source` into `dest` (the same as calling `$cs.File_CopyTree`) and then deletes `source` (the same as calling `$cs.File_DelTree`) — this is a copy-then-delete, not an atomic rename; `$false` does nothing and returns without error.

### Syntax

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

### Parameters

#### source (String)

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

#### dest (String)

Full path of the destination directory.

#### overwrite (Boolean)

If `dest` already exists: `$true` merges `source` into `dest` by copying then deleting `source`; `$false` leaves both directories untouched.

### Return value

None.

### Example

**PowerShell**

```powershell
$oldFolder = Join-Path $global:Packageroot "Temp"
$newFolder = Join-Path $global:Packageroot "Temp2"
$cs.File_RenameDir($oldFolder, $newFolder, $false)
```

Archive an old versioned install folder before laying down a fresh one, so a prior install is never lost:

```powershell
$currentInstall = Join-Path ${env:ProgramFiles(x86)} "Contoso\AppV1"
$backupFolder = Join-Path ${env:ProgramFiles(x86)} "Contoso\AppV1_backup"
if ($cs.File_ExistDir($currentInstall))
{
  $cs.Job_WriteLog("Archiving existing install to $backupFolder")
  $cs.File_RenameDir($currentInstall, $backupFolder, $true)
}
```

Merge a newly extracted profile template into an existing user data folder, overwriting any conflicting files:

```powershell
$stagingFolder = Join-Path $global:Packageroot "ProfileTemplate"
$targetFolder = Join-Path $env:ProgramData "Contoso\ProfileTemplate"
$cs.File_RenameDir($stagingFolder, $targetFolder, $true)
```

### Related functions

[$cs.File_RenameFile](/capainstaller/powerpacks/cs-file-renamefile/) [$cs.File_CopyTree](/capainstaller/powerpacks/cs-file-copytree/) [$cs.File_DelTree](/capainstaller/powerpacks/cs-file-deltree/) [$cs.File_ExistDir](/capainstaller/powerpacks/cs-file-existdir/)
