我有以下脚本,但它永远不会结束执行。解析脚本永不结束
可能是什么问题?我试图调试它,但显然它可以正确使用单个文件,但是当我将它扔到内容充满内容的文件夹失败时。
$path = split-path -parent $MyInvocation.MyCommand.Definition
$files = Get-ChildItem "$path\CodeForCertification\5_SourceCode\*" -Include *.c,*.h -Recurse | where{
! $_.PSIsContainer
}#$PSScriptRoot
ForEach ($file in $files){
$data = Get-Content -Path $file.FullName
$feature = Get-Content "$path\Disabled_Features.txt"
#[System.ArrayList]$Modifier
$nl=[Environment]::NewLine
[email protected]()
$flag=0
$data = $data | ForEach-Object -Begin {
$ignore = $false; $levels = 0
} -Process {
for($counter=0; $counter -lt $feature.Count; $counter++){
$parse = $feature[$counter]
if($_ -match "^#ifdef $parse" -And $flag -eq '0') {
$ignore = $true
$flag = 1;
}
}
if($ignore) {
if ($_ -match "^#ifdef") {
$levels++
}elseif ($_ -match "#endif") {
if($levels -ge 1) {
$levels--
if($levels -eq '0'){
$ignore = $false
}
}
}
}else {
$flag=0
$temp=$_
$_
$Modifier+="$temp"
}
}
$data | Out-File $file.FullName
}
呀,为什么不...... – Jackson
你有一些SAMP我们可以测试的文件?您的disabledFeatures和scrubbed源代码文件?你有没有尝试在文件之间放置一些输出行,让你知道它正在继续?你如何衡量循环缺乏进展?如果有更好的方法,很高兴知道这段代码应该做什么。 – Matt
您是否使用断点在PowerShell ISE中进行调试?您的代码可能会很慢,部分原因是您在每次迭代中都重新读取txt文件,并在默认模式下使用Get-Content,对于大量文件有很多行,速度非常慢。 – wOxxOm