Hello, VB.NET 2010
I am self taught at VB.NET and have not worked with it for a couple of years. I have code that works fine but I would like to know if there is a better way.
What I want is the most resently dated file. I am puting the date and filename into a list in order to sort it. I then look at the last array element and by finding the pipe I can then get the filename.
As I say this works (for both LIST and ARRAYLIST) but I am trying to see if the code in red can be modified. Is there a better way?
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
I am self taught at VB.NET and have not worked with it for a couple of years. I have code that works fine but I would like to know if there is a better way.
Code:
Dim sfFiles As New IO.DirectoryInfo("mypath")
Dim sfFileList As IO.FileInfo() = sfFiles.GetFiles(".txt")
Dim sfFileInfo As IO.FileInfo
Dim farray As New List(Of String)
Dim ACounter As Int16 ' counter used to get last file
Dim InputFile AS String
For Each sfFileInfo In sfFileList
farray.Add(sfFileInfo.CreationTime.ToString("u") & "|" & sfFileInfo.Name)
Next
farray.Sort()
ACounter = farray.Count - 1
InputFile = [COLOR=red]farray(ACounter).ToString.Substring(farray(ACounter).ToString.IndexOf("|") + 1, 12)[/color]
As I say this works (for both LIST and ARRAYLIST) but I am trying to see if the code in red can be modified. Is there a better way?
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!