Click here to Skip to main content
11,929,675 members (60,226 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
I have been working with a software program from hp called openview and it delivers and installs software on all our computers. It creates these logs each time it runs a software connect and I have to open and look through and im tired of having to search for it and then open it.

now i have deen using the below code to get all the files that have *_mach.log. I need help going from that list and open the one that has the highest number in front of it. so a normal log file looks like this 20120516_mach.log, and the numbers you see are the date it was created which also lets us know when a software connect last ran.

i have been using the below code to just get the file names and what i really want to do is once it has the most current log is to open it with notepad. now the below code i have going to a list view for right now and i don't want to use it in the end result. What i want is when you click the button to open the log it opens the most current file in notepad.

code for searching the folder:

Dim di As New IO.DirectoryInfo("C:\Users\Zachary\Desktop\Log")
Dim diar1 As IO.FileInfo() = di.GetFiles("*_mach.log")
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1

the code i m using to open files with notepad:(example)
Process.Start("notepad.exe", "\\" & strcomputer & "\C$\Windows\System32\drivers\etc\HOSTS")

help would be great...
Posted 25-May-12 10:12am
SAKryukov 25-May-12 16:06pm
What about WinFomrs? This is irrelevant. Better remove this tag, add ".NET".
Why would you use Notepad, ever, if with Forms you can use TextBox?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Probably you mean "most recent file". Most recently created or most recently written?

After you get all files in question in the form of the instance of System.IO.FileInfo, you can use System.IO.CreationTime or System.IO.LastWriteTime (depending on what time do you need) and compare time. Please see:[^].

Remember that the time resolution is not high, it's a millisecond. Please see:[^].

By the way, many are confused about how to compare the instances of System.DateTime. The answer is simple: use the operator "<" or ">". Please see:[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100