GetNewestFile function to get path of the last modified file (Visual Basic)

Send Us a Sign! (Contact Us!)
Word PDF XPS Text

This function will let us to get the [gs filename] of the newest (based on last modified date property of the file), complete with path. This [gs function] will work on Visual Basic and Visual Basic Script.

[tweet]

Function GetNewestFile(ByVal sPath)

sNewestFile = Null
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
'Enumerate the files in the folder in order to find the last file
For Each oFile In oFiles
On Error Resume Next
If IsNull(sNewestFile) Then
sNewestFile = oFile.Path
dPrevDate = oFile.DateLastModified
ElseIf dPrevDate < oFile.DateLastModified Then
sNewestFile = oFile.Path
End If
On Error Goto 0
Next
GetNewestFile = sNewestFile
MsgBox(GetNewestFile)
End Function

How to use it

In a [gs script], use it directly like:

sPath = "E:\"

GetNewestFile(sPath)

SOURCE

LINK (Heelpbook.net)

LANGUAGE
ENGLISH

2 thoughts on “GetNewestFile function to get path of the last modified file (Visual Basic)”

Comments are closed.