Update-Dir2Dir.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# Update-Dir2Dir.ps1
#
function Update-Dir2Dir {
    <#
    .SYNOPSIS
     Merges template directory into target one
    .DESCRIPTION
     Will update TargetDir
    .EXAMPLE
    # Simple use
      Update-Dir2Dir -TargetDir="C:\work\target" -TemplateDir="C:\work\Template"
    #>
    
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$True)]
        [string]$TargetDir,

        [Parameter(Mandatory=$True)]
        [string]$TemplateDir

    )
    
    [TreeWalk.Runner]::Defaults
    [TreeWalk.Runner]::runnerType = "FilteredTree"    
    [TreeWalk.Runner]::outputProcessorType = "PSScript"
    
    $InputFullPath = ""
    $CurDir = (pwd).Path        

    if(![System.IO.Path]::IsPathRooted($TemplateDir)) {        
        $InputFullPath = "$CurDir\$TemplateDir\"        
    }
    else {
        $InputFullPath = "$TemplateDir\"
    }    

    $OutFullPath = ""
    if( ![System.IO.Path]::IsPathRooted($TargetDir) ) {
        $OutFullPath = "$CurDir\$TargetDir\"
    }
    else { 
        $OutFullPath = "$TargetDir\"
    }
    if(![System.IO.Directory]::Exists($OutFullPath)) {
        [System.IO.Directory]::CreateDirectory($OutFullPath)
    }
    Write-Verbose "TreeWalk.Runner $InputFullPath $OutFullPath $TreeWalkPath\FUPD\ "
    [TreeWalk.Runner]::Run($InputFullPath,$OutFullPath,"$TreeWalkPath\FUPD\")
         
}