【问题标题】:Getting txt not found error when running this script运行此脚本时出现 txt not found 错误
【发布时间】:2017-05-22 04:46:41
【问题描述】:

运行此脚本时出现此错误:

使用“1”参数调用“匹配”的异常:“值不能 无效的。参数名称:input" at V:\compiler\shitter2.ps1:3 char:1 + $tables = $regex.matches((GC v:\compiler\test.txt -raw)).groups.value + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentNullException

这是脚本代码:

$Path = 'V:\compiler\po.htm'
[regex]$regex = "(?s)<TABLE ID=.*?</TABLE>"
$tables = $regex.matches((GC v:\compiler\test.txt -raw)).groups.value
ForEach($String in $tables){
$table = $string.split("`n")
$CurTable = @()
$CurTableName = ([regex]'TABLE ID="
([^"]*)"').matches($table[0]).groups[1].value
$CurTable += ($table[1] -replace "</B></TH><TH><B>",",") -replace "</?
(TR|TH|B)>"
$CurTable += $table[2..($table.count-2)]|ForEach{$_ -replace "</TD>
<TD>","," -replace "</?T(D|R)>"}
$CurTable | convertfrom-csv | export-csv "$CurTableName.csv" -notype
}

【问题讨论】:

  • 错误消息暗示GC v:\compiler\test.txt -raw 正在产生空值。如果我使用虚拟文件名尝试您的示例,我会收到相同的消息,前面是一条错误消息,指出该文件不存在。你的文件路径正确吗?你的文件内容是什么?这是完整的错误信息吗?

标签: powershell


【解决方案1】:

您可能忘记了使用[1] 访问条目:

$tables = $regex.matches((GC v:\compiler\test.txt -raw)).groups[1].value

【讨论】:

  • 感谢回复,添加 [1] 后我仍然收到相同的错误
猜你喜欢
  • 2022-07-05
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 2016-01-25
  • 1970-01-01
  • 2021-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多