Use PowerShell with a Folder Picker to Copy a Specific Folder
Problem
During development, theme folders for different sites often need to be manually copied over. Let's automate this with PowerShell.
Approach
- Use the powerful built-in Windows robocopy command for copying.
- Provide a default folder path, and use a .NET Framework dialog component so the user can still pick the folder they want to copy.
Usage
- Right-click create_desktop_workspace.ps1 and run it with PowerShell.

- Select the Theme folder you want to copy.

- The script will copy the Theme from the selected folder into the project.

Code
Function Get-Folder($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")|Out-Null
$foldername = New-Object System.Windows.Forms.FolderBrowserDialog
$foldername.Description = "Select a folder"
$foldername.rootfolder = "MyComputer"
$foldername.SelectedPath = $initialDirectory
$foldername.ShowNewFolderButton = $false
if($foldername.ShowDialog() -eq "OK")
{
$folder += $foldername.SelectedPath
}else{
exit
}
return $folder
}
$defaultFolderName="Theme1"
$currentPath = (Get-Item .).FullName + '\Src\Web.Portal\' + $defaultFolderName ;
$desktopThemePath = Get-Folder($currentPath)
$pathArray = $desktopThemePath.Split("\")
$targetFolderName =$pathArray[$pathArray.length-1]
$desktopProjectSource="..\Portal\Portal\Portal.Web\Web"
robocopy $desktopThemePath $desktopProjectSource /E
pause





























Comments