Re: FileExists Wildcard + newest file by McKirahan
McKirahan
Mon Jan 03 11:53:23 CST 2005
"bmills123" <pha3drus@prodigy.net> wrote in message
news:1104770593.396009.176480@z14g2000cwz.googlegroups.com...
> I am writing a script to read a log file that is dumped at random
> times. All of the logs are in the same location but the name contains a
> timestamp of sorts.
>
> example:
> c:\log\log2004-11-16-13-12.log
>
> How do I search the directory for "c:\log\log*" and open the newest one
> for reading?
>
Will this help? Watch for word-wrap.
'*
'* Identify latest .log file
'*
Option Explicit
'*
'* Declare Constants
'*
Const cVBS = "log_file.vbs"
Const cFOL = "C:\Log\"
Const cLOG = "log*.log"
'*
'* Declare Variables
'*
Dim strFIL
Dim strGF2
'*
'* Declare Objects
'*
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGF1
Dim objGF2
'*
'* Files in Folder
'*
If Not objFSO.FolderExists(cFOL) Then WScript.Quit
Set objGF1 = objFSO.GetFolder(cFOL)
Set objGF2 = objGF1.Files
For Each strGF2 in objGF2
If Left(strGF2.Name,3) & "*" & Right(strGF2.Name,4) = cLOG Then
strFIL = strGF2.Name
End If
Next
'*
'* Destroy Objects
'*
Set objFSO = Nothing
Set objGF1 = Nothing
Set objGF2 = Nothing
'*
'* Results
'*
MsgBox strFIL,vbInformation,cVBS
The "For Each" loop returns file in order by DateCreated.