【问题标题】:VBScript - email when file not created todayVBScript - 今天未创建文件时发送电子邮件
【发布时间】:2012-09-19 20:01:31
【问题描述】:

目标:运行一个每天检查文件夹的 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 

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    基于您已经完成的想法,如果找到今天的文件,但必须检查所有文件以确保今天的文件丢失,逻辑将是:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-07
      • 2015-07-05
      • 2012-04-16
      • 1970-01-01
      相关资源
      最近更新 更多