Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

read contents of file and return boolean

Posted on 2007-04-09
11
Medium Priority
?
196 Views
Last Modified: 2013-11-26
i  have a log file that is created with the following syntax

{
-name "Adidas Blend"
-start -cron 30 9 * * 7
-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -pwd CUR_DIR
-action -print "Current directory is %CUR_DIR%"
-action -cd "D:\DMS_Live\ADS_Blend"
-action -pwd CUR_DIR
-action -print "After CD, current directory is %CUR_DIR%"
-action -spawn "ADS_Blend.exe"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"
}

Each day this file adds a new line.  I need to be able to right some vb.net code that opens the file and checks to see that the two lines are created each day.  maybe it wiill return a boolean value.
0
Comment
Question by:Robb Hill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18878082
A boolean value with respect to what?...
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18878139
the program should open the file...verify the last two lines are there ....if they are both there..then return true..else return false.  These two lines are appended to the file everytime the job runs.  Im trying to create an alert when this file is missing these two lines on a given day.

-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"

0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18878261
Ok...do those two lines have anything to indicate WHEN they were added?

Does "%c%" get replaced by something in the actual file or is that literally what is there?

Or do I have it all wrong?

Is the file recreated each day with the stuff you originally posted and then the two lines from your last post are added at some point?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 11

Author Comment

by:Robb Hill
ID: 18878336
each day a process runs.  This scheduler program called wincron runs the exe files....
This program appends to a log file.  The %c% will put a date at the end of the log.

And yes, the file created each day is an append of the original file.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18878810
"The %c% will put a date at the end of the log."

In what format will the date be so we can check against the current date?
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18881804
12/21/03 11:37:54
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18890555
This is what I have so far.  I wish there was a way so that my date test was always the current Saturday of the month.

'Open a file for reading
        Dim FILENAME As String = "c:/Scheduler.log"
        Dim looptest As Boolean = True

        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        Dim contents As String = objStreamReader.ReadToEnd()

        Dim a() As String = Split(contents, vbCrLf)
        Dim now As DateTime = DateTime.Now.ToShortDateString
        For i As Integer = 0 To a.Length - 1

            Dim strArray() As String = a(i).Split("-")
            strArray(1) = LTrim(strArray(1))
            Dim strDate() As String = strArray(1).Split(" ")

            If strDate(0) = now Then
                looptest = True
                Exit Sub
            Else
                looptest = False
            End If
        Next
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 18891917
How about something like?...

(This is the .Net Framework 2.0 TA so I assume you are using VB.Net 2005)

    Private Function FileUpdated() As Boolean
        Dim fileName As String = "c:\Scheduler.log"
        Dim contents As String = My.Computer.FileSystem.ReadAllText(fileName)
        Dim lines() As String = contents.Replace(vbCrLf, vbCr).TrimEnd(vbCr).Split(vbCr)
        Dim curSaturday As Date = DateTime.Today.AddDays(DayOfWeek.Saturday - DateTime.Today.DayOfWeek)
        Dim lastLine As String = lines(lines.GetUpperBound(0))
        If lastLine.IndexOf("ADS Blend Task End Time") <> -1 Then
            Dim lastDash As Integer = lastLine.LastIndexOf("-")
            Dim strDateTime As String = lastLine.Substring(lastDash + 1).Trim
            Dim lastDateTime As DateTime
            If DateTime.TryParse(strDateTime, lastDateTime) Then
                Dim lastDate As Date = lastDateTime.Date
                If lastDate.CompareTo(curSaturday) = 0 Then
                    Return True
                End If
            End If
        End If
        Return False
    End Function
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892111
I really like your use of my...im still trying to learn all the advantages of some of the new 2.0 stuff.
Do you have any recomendations.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 18892133
Don't have any recommendations sorry...I'm still learning them myself!  =)
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892151
Well thanks again.  
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question