gpt4 book ai didi

VBScript - 今天未创建文件时发送电子邮件

转载 作者:行者123 更新时间:2023-12-04 19:36:59 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于VBScript - 今天未创建文件时发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12502011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com