Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET WinForm
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
    ListBox1.Items.Add(dra)
Next
 

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 9:12am
Comments
SAKryukov at 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?
--SA

1 solution

Rate this: bad
good
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:
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx[^].
 
Remember that the time resolution is not high, it's a millisecond. Please see:
http://social.msdn.microsoft.com/Forums/eu/csharpgeneral/thread/bed97747-923d-4078-9ae3-04e0b0192342[^].
 
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:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^].
 
—SA
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 225
1 Sergey Alexandrovich Kryukov 167
2 _Amy 155
3 CHill60 130
4 Manfred R. Bihy 130
0 OriginalGriff 7,320
1 Sergey Alexandrovich Kryukov 6,043
2 Maciej Los 3,754
3 Peter Leow 3,448
4 CHill60 2,572


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 25 May 2012
Copyright © CodeProject, 1999-2014
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