PowerShell cab圧縮関数

cab圧縮関数を作成してみました。

# パクリですけどね。

 

#######################################
# compress to cab
# Usage: CompressCab "target"
#######################################
function MakeCabFile([String]$targetPath, [String]$outPath, [String]$cabName)
{
    if($targetPath -eq $null){
        Log "ERROR" "targetPathが指定されていません"
        return
    }

    if($outPath -eq $null){
        Log "ERROR" "outPathが指定されていません"
        return
    }

    if($cabName -eq $null){
        Log "ERROR" "cabNameが指定されていません"
        return
    }

    $ddfFile = [System.IO.Path]::GetTempFilename()
    $ddfHeader =@"

;*** MakeCAB Directive file
;
.OPTION EXPLICIT
;.Set CabinetNameTemplate=$cabName.*.cab
.Set CabinetNameTemplate=$cabName.cab
.set DiskDirectory1=$outPath
.set MaxDiskSize=CDROM
.set Cabinet=on
.Set Compress=on
"@
   
    # ディレクティブファイル作成
    $ddfHeader | Out-File -filepath $ddfFile -force -encoding ASCII

    Write-Host "debug:" + $targetPath
    Get-ChildItem -path $targetPath | ?{!$_.psiscontainer} | %{
        '"' + $_.fullname.toString() + '"' |
        Out-File -filepath $ddfFile -encoding ASCII -append
    }

    makecab /f $ddfFile
     del $ddfFile
}