Get Last Modified File from Folder

Here is sample code to get last modified file from folder

Dim directory As DirectoryInfo = New DirectoryInfo(“C:\Temp”)
Dim filter As String = txtFileName.Text

If directory.GetFiles(txtFileName.Text).Count > 0 Then
    Dim myFile As FileInfo = directory.GetFiles(filter).OrderByDescending(Function(f) f.LastWriteTime).First()
    MsgBox(myFile.Name)
Else
    MsgBox(“No files found”)
End If

 

(Visited 173 times, 2 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Last Modified File from Folder

Here is sample code to get last modified file from folder

Dim directory As DirectoryInfo = New DirectoryInfo(“C:\Temp”)
Dim filter As String = txtFileName.Text

If directory.GetFiles(txtFileName.Text).Count > 0 Then
    Dim myFile As FileInfo = directory.GetFiles(filter).OrderByDescending(Function(f) f.LastWriteTime).First()
    MsgBox(myFile.Name)
Else
    MsgBox(“No files found”)
End If

 

(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *