$cs.File_RenameDir
Description
Section titled “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
Section titled “Syntax”$cs.File_RenameDir(string source, string dest, bool overwrite = true)
Parameters
Section titled “Parameters”source (String)
Section titled “source (String)”Full path of the directory to rename or move. Must exist.
dest (String)
Section titled “dest (String)”Full path of the destination directory.
overwrite (Boolean)
Section titled “overwrite (Boolean)”If dest already exists: $true merges source into dest by copying then deleting source; $false leaves both directories untouched.
Return value
Section titled “Return value”None.
Example
Section titled “Example”$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:
$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:
$stagingFolder = Join-Path $global:Packageroot "ProfileTemplate"$targetFolder = Join-Path $env:ProgramData "Contoso\ProfileTemplate"$cs.File_RenameDir($stagingFolder, $targetFolder, $true)Related functions
Section titled “Related functions”$cs.File_RenameFile $cs.File_CopyTree $cs.File_DelTree $cs.File_ExistDir