Exection for FilesSerch

$pathTop = [Environment]::GetFolderPath('Desktop')
$pathPs = Split-Path -Parent $MyInvocation.MyCommand.Path
cd $pathPs
. .\Func_NamesAndPaths.ps1
. .\Func_Form.ps1
. .\Func_FormParts.ps1
. .\Func_FormDialog.ps1
. .\Func_Files.ps1
. .\Func_MyExplorer.ps1
. .\Func_BKedit.ps1
. .\Func_FormConfig.ps1

function ShowFormSerchFile($pathRoot,$FormOwner,$InitName){
    $StrRet = GetByFormInputTxb "File Name" -MinLength 2 -FormOwner $FormOwner -InitText $InitName `
                -ShowFormNum -ShowFormChar
    if([bool]$StrRet -eq $false){ return }
    $StrSerch ="*$StrRet*"
    $outPaths = SerchFilePathByTxt $StrSerch $pathRoot
    Write-Host ( [string]$outPaths.count + " folders found" )
    Write-Host $outPaths
    if( $outPaths.count -eq 1){
        $msg = "Success Found. `n`n "+ ($outPaths.count) + " folders found. `nOpen it."
        ResByMsgbox -Text $msg 
        . "$pathTop\ps\Func_MyExplorer.ps1"
        MyExplorer -pathIn $outPaths[0] -nameInWild $StrSerch -FilterIn $StrSerch
        return
    }
    if( $outPaths.count -ge 1 -and $outPaths.count -le 3){
        $msg = "Success Found. `n`n "+ ($outPaths.count) + " folders found. `nOpen it."
        ResByMsgbox -Text $msg 
        foreach($el in $outPaths){ Invoke-Item $el }
        return
    }
    if( $outPaths.count -gt 3){
        $msg = "Found too many result. `n`n"+ ($outPaths.count) + " folders found. `nRetry it."
        ResByMsgbox -Text $msg 
        ShowFormSerchFile $pathRoot $FormOwner $StrRet
    }
    if( $outPaths.count -eq 0){
        $msg = "Found no result. `n`nRetry it."
        ResByMsgbox -Text $msg 
        ShowFormSerchFile $pathRoot $FormOwner $StrRet
    }
}

$NmFileConfig = "Config_SerchFiles.txt"

function ShowFormTop(){

    # Table 定義
    $Table1 = GetNewTable -nCol 4 -nRow 6 -SideMargin 5 

    # Controls 定義
    $Lab1= GetNewLabel "Menu" -BottomLeft | SetToTable $Table1 -nRow 0 -spanCol 2
    $Btn1 = GetNewButton "2D File-Serch" | SetToTable $Table1 -nRow 1 -spanCol 2
    $Btn2 = GetNewButton "2D Data Update" | SetToTable $Table1 -nRow 3 -spanCol 2
    $Btn3 = GetNewButton "Config" | SetToTable $Table1 -nRow 4 -spanCol 2

    $Btn4 = GetNewButton "BK File-Serch" | SetToTable $Table1 -nRow 1 -nCol 2 -spanCol 2
    $Btn5 = GetNewButton "BK Data Update" | SetToTable $Table1 -nRow 3 -nCol 2 -spanCol 2


    # Event   
    $ClickBtn1={
        $pathRoot1 = GetConfigContent $NmFileConfig -NumPath 0        
        $Form1.Visible=$false
        ShowFormSerchFile $pathRoot1 -FormOwner $Form1
        $Form1.Visible=$true
    }
    $Btn1.Add_Click($ClickBtn1)
    $ClickBtn2={    
        $result = ResByMsgbox -ConfirmForExec -Text "Update 2D-Data files.`nExec OK ?"
        if($result -eq $resYes){
            $pathRoot1 = GetConfigContent $NmFileConfig -NumPath 0
            $keyWild2 = (GetConfigContent $NmFileConfig -NumWord 0)
            if([bool]$pathRoot1 -and [bool]$keyWild2 ){
                OutTxtNamesAndPaths $pathRoot1 $keyWild2
            }else{
                ResByMsgbox -Text "Error: Config is nothing" -Information
            }
        } 
    }
    $Btn2.Add_Click($ClickBtn2)

    # Config Buttun
    $ClickBtn3={
        $Form1.Visible=$false
        $ItemsConfig = AddItemConfig -ItemType "Path" -ItemName "SerchRoot" | 
                        AddItemConfig -ItemType "Path" -ItemName "BKMoto" | 
                        AddItemConfig -ItemType "Path" -ItemName "MyBK" | 
                        AddItemConfig -ItemType "Word"
        ShowFormConfig -FormOwner $Form1 -NmFileConfig $NmFileConfig -ItemsConfig $ItemsConfig
        $Form1.Visible=$true
    }
    $Btn3.Add_Click($ClickBtn3)

    $ClickBtn5={    
        $result = ResByMsgbox -ConfirmForExec -Text "Update BK-Data files.`nExec OK ?"
        if($result -eq $resYes){
            Write-Host "---Update BK-Data--------------------------"

            $pathCopy = GetConfigContent $NmFileConfig -NumPath 1
            $pathMyBK = GetConfigContent $NmFileConfig -NumPath 2
            
            cd $pathCopy
            UpdateCopy $pathMyBK 
            cd $pathMyBK
            RenameBK $pathMyBK
            RemoveBK $pathMyBK
            DocsToPdfBK $pathMyBK
            Write-Host "---Update BK-Data finished------------------"
            ResByMsgbox "Update BK-Data executed."
        } 
    }
    $Btn5.Add_Click($ClickBtn5)

    # Form 定義
    $Form1 = GetNewForm -text "Top Form" 

    # Form Event
    $Form1.Add_Shown({
        $Form1.Activate()        
    })
    # Form 表示
    $Form1.Controls.Add($Table1)

    $res = $Form1.ShowDialog() 
    if($res -eq [Windows.Forms.DialogResult]::OK){

    }
}

ShowFormTop