Reading Log Files

I needed to look at log files and made what I thighs would be a simple application that looks at log files and have come across a problem where some log files can be seen but are not displayed in a TextArea.

Here is a piece of the code I am using to display the info in a text area

[code] my_item_selected = Window1.Listbox1.Cell(ListIndex, 0)
my_f = SpecialFolder.VarLog.Child(my_item_selected)

t = TextInputStream.Open(my_f)

Window1.MyTextArea.Text = “”
If t <> Nil Then
// Read all of t into myTextArea.text
mytext = t.ReadAll.ToText
'mytext = t.ReadAll
Window1.MyTextArea.Text = mytext
// close the file so that other applications can use it
// the file could not be a read as a text file
MsgBox(“The selected file is not a text file.”)
End If

Exception err as TypeMismatchException
MsgBox “Tried to retype an object!” + my_f.Name
Exception err as NilObjectException
MsgBox “Tried to access a Nil object!” + my_f.Name
Exception err as RuntimeException // NOT RECOMMENDED
MsgBox "Cannot open that file type: " + my_f.Name[/code]

In the above I place all items - folders & files - in a listbox that are located in FolderItem = SpecialFolder.VarLog

Here is the code used to prepare Listbox on open

[code]ColumnCount = 3
ColumnWidths = “50%,35%,*”

Me.HasHeading = True
Me.Heading(0) = “Dir/File”
Me.Heading(1) = “Date”
Me.Heading(2) = “Size”

Dim thisFolder As FolderItem = SpecialFolder.VarLog
Dim count As Integer = thisFolder.Count

f = New FolderItem("/var/log", FolderItem.PathTypeShell)
RowTag(0) = f.GetSaveInfo(GetFolderItem(""))



Here is the code that expands a row in the listbox

[code]Dim itemsAdded, size As Integer
Dim f As FolderItem
Dim sizeStr As String
Dim today As New Date

Dim vol As New FolderItem
f = vol.GetRelative(RowTag(row))

For i As Integer = 1 To f.Count
If f.Item(i).Visible Then
If f.Item(i).Directory = True Then //Checks if the file is a folder
Me.AddFolder(f.Item(i).Name) //This adds a new folder to the list
Me.Addrow(f.Item(i).Name) //Lines like this add a row to the listbox, which stand for a file in the folder being viewed
End If

itemsAdded = itemsAdded+1

//put the path in a non-visible column
RowTag(row + itemsAdded) = f.Item(i).GetSaveInfo(GetFolderItem(""))

//put in the mod date
If f.Item(i).ModificationDate.DayofYear = (today.DayofYear-1) Then
  Cell(row+itemsAdded, 1) = "Yesterday"
  If f.Item(i).ModificationDate.ShortDate = today.ShortDate Then
    Cell(row+itemsAdded, 1) = "Today"
    Cell(row+itemsAdded, 1) = f.Item(i).ModificationDate.AbbreviatedDate
  End If
End If

//handle the size column
If f.Item(i).Directory Then
  sizeStr = "-"
  size = f.Item(i).Length
  If size < 1000 Then
    sizeStr = Str(size)+" bytes"
    If size<1000000 Then
      sizeStr = Trunc(size/1000,0)+"K"
      sizeStr = Trunc(size/1000000,2)+"MB"
    End If
  End If
End If

Cell(row+itemsAdded, 2) = sizeStr

End If //it’s visible

Exception e As OutOfBoundsException
MsgBox "Error: "+ e.Message[/code]

When you double click either the folder is expanded or the file is displayed in a TextArea

To check I placed text from readily in a variable. When we get to this step I can see the text from that file in the variable however when it is placed in TextArea nothing is there

I have played around with encoding and still nothing is viewable namely in the userlog file. However if you double click the text is viewable in leafed or other text editors