2012-09-19 41 views
3

目标:运行每天检查文件夹的VBScript,并报告当天是否没有文件保存。忽略前几天存在的文件。VBScript - 今天未创建文件时的电子邮件

我需要检查当天是否没有创建文件并发送电子邮件。如果当天创建了一个文件,那么我希望脚本什么都不做 - 不通知。我发现这个代码,但它的对面,发送电子邮件,如果该文件存在,并且不执行任何操作,如果它丢失:

option explicit 
dim myMail 
dim fileSystem, folder, file 
dim path 
path = "C:\Temp" 
Set fileSystem = CreateObject("Scripting.FileSystemObject") 
Dim myDate 
myDate = dateadd("d", -1, FormatDateTime(Now, 2)) 
Set folder = fileSystem.GetFolder(path) 
for each file in folder.Files 
    if file.DateCreated > myDate then 
    'WScript.Echo file.Name & " last modified at " & file.DateCreated 
     SendEmail 
    'WScript.Echo "this should have sent an email." 
    end if 
next 

Function SendEmail() 
    'this works 
End Function 

回答

0

根据您都做了,如果今天的文件中找到的想法,但必须检查所有文件可以肯定,即今天的文件丢失,逻辑将是:

found = False 
For all files in folder 
    If today's file found 
     found = True 
     Exit For 
    End If 
Next 
If Not found Then 
    Send Email 
End If 
相关问题