This one alone does work.
If I try HandleReport -ReportName "123456.pdf"
it says matches
function HandleReport
{
param ( [string] $ReportName = "" )
if ( $ReportName -match "(\d{6})." ) {
$Result = $_ + " matches ..."
write $Result
}
}
Now I call it from a function which reads a directory:
for ($i=0; $i -lt $EventTypes.length; $i++) {
# $FU_Dir is correct and does exist.
dir $FU_Dir | foreach {
$ReportName = $_.name
HandleReport -ReportName $ReportName
}
}
Now I get:
Method invocation failed because [System.IO.FileInfo] doesn't contain a method named 'op_Addition'. At line:6 char:24 + $Result = $_ + <<<< " matches ..." + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound matches ...
maybe the $_.name
does not give back a string?
"(\d{6})."
... Did you want 6 digits followed by a period? You should use"(\d{6})\."
so you have a literal period instead of any character. – Matt