Reading random HTML input files of indiscriminate size I limit read up to 1000 lines or end /html tag. Works fine.
Problem is with small files and when /html tag is missing. I'd like to know when it got to the end.
Question: Is there a some sort of EOF property for that..?
$fileContents = (Get-Content -LiteralPath $filePath -totalcount 999)
ForEach ($line in $fileContents){
$LineNo = $LineNo +1;
if ((($line.ToLower().StartsWith("</html>"))) -or ($LineNo -gt 999) -or ??? END_OF_$fileContents ???)
{
# Do the rest of the processing in here...
}
}
Couple of days later, here is my final code to handle this (scroll to right);
$fileContents = (Get-Content -LiteralPath $filePath -totalcount 999)
ForEach ($line in $fileContents){
$LineNo = $LineNo +1;
if ((($line.ToLower().StartsWith("</html>"))) -or ($LineNo -gt 500) -or ($LineNo -ge $fileContents.Count))
{
# Do the rest of the processing in here...
}
}
The idea of doing it this way is to "bail out" of processing massive html files, but still be able to handle a little ones, even if they aren't properly formatted (common in email files).