gpt4 book ai didi

powershell - 即使没有人也能比赛

转载 作者:行者123 更新时间:2023-12-02 23:18:30 25 4
gpt4 key购买 nike

我试图在Powershell中使用-match查找字符串“ErrorCode”:1。我发现许多文件带有ErrorCode:1。问题是,当我打开一个由匹配表达式给出的文件进行检查时,我什至没有找到单词ErrorCode,而文件名仍然作为输出提供给我

我试图检查文件,但是许多文件都有我要搜索的字符串,但是许多文件却没有。

$fileNames = Get-ChildItem -Path $scriptPath -Recurse -Include *.data
$FoldersToRename = @() #initialize as array
foreach ($file in $fileNames) {
If (Get-Content $file | %{$_ -match '"ErrorCode":1'})
# If (Get-Content $file | %{$_ -match '"ErrorCode": [1-9]\d*'})
{
$FoldersToRename += Split-Path $file
echo $file
}
}

这是我作为输出得到的文件内容之一
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>

有人可以帮助解释该文件如何输出吗?

最佳答案

尝试分隔Get-Content命令。

$fileNames = Get-ChildItem -Path $scriptPath -Recurse -Include *.data
$FoldersToRename = @() #initialize as array
foreach ($file in $fileNames) {
$content = Get-Content $file
If ($content -match '"ErrorCode":1'})
# If (Get-Content $file | %{$_ -match '"ErrorCode": [1-9]\d*'})
{
$FoldersToRename += Split-Path $file
echo $file
}
}

关于powershell - 即使没有人也能比赛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58300299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com