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.
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 |
Hey dude, did you know? GetNewestFile function to get path of the last modified file (Visual Basic) – http://heelpbook.altervista.org/?p=34943 (Visit us on http://www.heelpbook.net) – Enjoy!
GetNewestFile function to get path of the last modified file (Visual Basic) http://heelpbook.altervista.org/2012/getnewestfile-function-to-get-path-of-the-last-modified-file-visual-basic/ via @HeelpBook