返回列表 发帖

[原创代码] powershell全局变量的使用

当使用 如下代码,调用 function processing_grep  操作每个文件时候,发现 变量 不能按照预期的增加,
,@(Get-ChildItem -Path $Path -Filter $Filter -Recurse | ?{$_.PsIsContainer -eq $false} |?{$_.name -match $Filtermatch} | %{processing_grep $_.FullName} )COPY
所以必须要修改为$global::cnt 才可以。
function processing_grep(  $file ){
    Write-Host "Processing :    $file "
    $global:cntr=$global:cntr+1
    Write-Host "Processing :    $global:cntr "
$str=[string]$cntr
    $tmp = "$str" + "`*file`*" + $file
Write-Host "Processing :    $tmp "
$tmp | out-file D:\aaa.dpl -append
}
COPY

返回列表