Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Locating the most recently modified file in a folder

Status
Not open for further replies.

DrSeussFreak

Programmer
Feb 16, 2007
149
US
Each day a new file named 'bkuparcfiles_09062007.log' is produced, and I need to e-mail it to myself and a co-worker. The problem is that, as you see that their is a date at the end, and it changes each day. How can I pick the file that has been most recently modified?'

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\adsmlogs\", _
    ForReading)

SendEmail "To", "From", "MARS - Daily Tivoli Report", strSearchThis

Sub SendEmail(strTo, strFrom, strSubject, strMsg)
    schema = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/"[/URL]
    SmtpServer = "SMTP"

    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = strFrom
    objEmail.To = strTo
    objEmail.Subject = strSubject
    objEmail.Textbody = strMsg

    objEmail.Configuration.Fields.Item (schema & "sendusing") = 2
    objEmail.Configuration.Fields.Item (schema & "smtpserver") = SmtpServer
    objEmail.Configuration.Fields.Item (schema & "smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top