Mark Ku's Blog
首頁 關於我
用 Power shell 跳窗指定複製的資料夾
PowerShell
用 Power shell 跳窗指定複製的資料夾
Mark Ku
Mark Ku
May 03, 2021
1 min

用 Power shell 跳窗指定複製的資料夾

問題

目在開發階段,不同網站的樣式 ( Theme )資料夾,經常需要手動覆蓋,用Powershell 將其自動化。

作法

  1. 複製採用 windows 內建強大的 robocopy 指令。
  2. 預設資料夾目錄,透過 net framework 跳窗元件,仍可以選擇想要複製的資料夾目錄。

使用方式

  1. 對 create_desktop_workspace.ps1 右鍵,用 PowerShell 執行

  1. 選取要 copy 的 Theme Folder

  1. 腳本就會將指定資料夾的 Theme 複製到專案中

程式碼

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



Tags

Mark Ku

Mark Ku

Software Developer

8年以上豐富網站開發經驗,直播系統、POS系統、電子商務、平台網站、SEO、金流串接、DevOps、Infra 出身,帶過幾次團隊,目前專注於北美及德國市場電商網站開發團隊。

Expertise

前端(React)
後端(C#)
網路管理
DevOps
溝通
領導

Social Media

facebook github website

Related Posts

Reduce the risk of manual deployment using powershell and beyondcompare
Reduce the risk of manual deployment using powershell and beyondcompare
June 27, 2023
1 min

Quick Links

關於我

Social Media