I am trying to write a script to email the newest / latest NTBackup backup
log in a directory. We backup the system state twice a day and would like
the log to emailed via the same vbscript.

I know how to send the email, I need help with finding the newest file in
the given directory.

Since we do two backups a day (07:00 and 21:00), and ntbackup increments the
log file by one each time, how do I set the latest filename and path to be a
varible to be used later?

Thanks
--
Thank You,

Keith Templin

Re: Find Newest File by Carey

Carey
Thu May 11 13:55:41 CDT 2006

Hi Kieth,

Try this, you can re package this part as a function and pass the
parameters into it.

Option Explicit
Dim FilePath
Dim OlderThan
Dim fs, ObjDirectory
Dim TheFiles, File
Dim sFileType
' Set path to start from:
FilePath = "Set path to start from"
sFileType = "log" 'Only those with .log extention
OlderThan = (Now() - .5) ' older than ? days

'Set System Objects
Set fs = CreateObject("Scripting.FileSystemObject")
Set ObjDirectory = fs.GetFolder(FilePath)
Set TheFiles = objDirectory.Files

'Read through Files
For Each File in TheFiles
if right(File.Path,3)=sFileType then
If (GetFileDate(File.Path) < OlderThan) Then
wscript.echo "This is you old file" & (File.Path)
end if
end if
Next

wscript.Quit

Function GetFileDate(theFile)
Dim oFile
Set oFile = fs.GetFile(theFile)
GetFileDate = oFile.DateLastModified
End Function 'GetFileDate()