运行此脚本时,找不到txt错误

时间:2017-05-22 04:46:42

标签: powershell

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

  

使用“1”参数调用“匹配”的异常:“值不能   空值。参数名称:输入“在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
}

1 个答案:

答案 0 :(得分:0)

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

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