在这里,我要获取的文件夹列表中包含具有ErrorCode> 0值的文件。
这是我到目前为止所做的。
$fileNames = Get-ChildItem -Path $scriptPath -Recurse -Include *.data
$FoldersToRename = @() #initialize as array
foreach ($file in $fileNames) {
If (Get-Content $file | %{$_ -match '"ErrorCode": 0'})
{
echo "matched"
}
现在我有.data文件,该程序正在搜索该文件。它包含一个值为“ ErrorCode”:value的对象。我只想在该值大于零时执行一些操作。
我该如何解决?
答案 0 :(得分:1)
一种方法是这样的:
Get-ChildItem -Path $scriptPath -Filter *.data |
ForEach-Object {
if((Get-Content -Path $_.FullName -Raw) -match '"ErrorCode": [1-9]\d*') {
"Matched"
}
}