Solved

read contents of file and return boolean

Posted on 2007-04-09
11
192 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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 500 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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