Vbscript以确定文件夹中的文件是否包含某些字符,并检查这些字符上的修改日期
我很难让它工作。我一直收到以下错误“Expecting then line 23”错误出现在第一个If File.Name包含节的地方 我知道这可能是我错过的一件很简单的事情,但我一生都看不到它。非常感谢您的帮助Vbscript以确定文件夹中的文件是否包含某些字符,并检查这些字符上的修改日期,vbscript,Vbscript,我很难让它工作。我一直收到以下错误“Expecting then line 23”错误出现在第一个If File.Name包含节的地方 我知道这可能是我错过的一件很简单的事情,但我一生都看不到它。非常感谢您的帮助 reportDate = date dtMonth = Month(reportDate) If dtMonth < 10 Then dtMonth = "0" & dtMonth End If dtDay = Day(reportDate) If dtDay &
reportDate = date
dtMonth = Month(reportDate)
If dtMonth < 10 Then
dtMonth = "0" & dtMonth
End If
dtDay = Day(reportDate)
If dtDay < 10 Then
dtDay = "0" & dtMonth
End If
dtYear = Year(reportDate)
saveFormatDate = dtYear & dtMonth & dtDay
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
Set goodFile = 0
Set badFile = 0
Set goodFileName = "To_Vendor_" & saveFormatDate
For Each file in fso.GetFolder("C:\Data_Files").Files
If file.Name contains(goodFileName) Then
recentDate = File.DateLastModified
If recentDate > DateAdd("H",-6,Now) Then
goodFile = goodFile + 1
Else
badFile = badFile + 1
End If
Else
' Do nothing
End If
Next
If badFile > 0 Then
wscript.echo "No files created within the last 6 months"
Else
If goodFile > 0 Then
'execute batch file eventually to initiate SFTP process
'not adding this until working
wscript.echo "Files are going to be sent."
Else
wscript.echo "No good files to be sent."
End if
End If
wscript.quit
reportDate=date
dtMonth=月份(报告日期)
如果dtMonth<10,则
dtMonth=“0”和dtMonth
如果结束
dtDay=天(报告日期)
如果dtDay<10,则
dtDay=“0”和dtMonth
如果结束
dtYear=年(报告日期)
saveFormatDate=dtYear&dtMonth&dtDay
设置fso=CreateObject(“Scripting.FileSystemObject”)
Set recentFile=Nothing
设置goodFile=0
设置badFile=0
将goodFileName=“设置为\u供应商\u”&保存格式日期
对于fso.GetFolder(“C:\Data\u Files”).Files中的每个文件
如果file.Name包含(goodFileName),则
recentDate=File.DateLastModified
如果recentDate>DateAdd(“H”、-6,现在),则
goodFile=goodFile+1
其他的
badFile=badFile+1
如果结束
其他的
“什么也不做
如果结束
下一个
如果badFile>0,则
wscript.echo“过去6个月内未创建任何文件”
其他的
如果goodFile>0,则
'最终执行批处理文件以启动SFTP流程
“在工作之前不添加此项
wscript.echo“将发送文件。”
其他的
wscript.echo“没有要发送的好文件。”
如果结束
如果结束
wscript.quit
我看到一些问题
dtDay = "0" & dtMonth
我想你是说这个吧
dtDay = "0" & dtDay
顺便说一句,这里有一个单衬垫垫像这样的东西:
dtDay = Right("0" & Day(reportDate), 2)
Set recentFile = Nothing ' This isn't being used at all
Set goodFile = 0
Set badFile = 0
Set goodFileName = "To_Vendor_" & saveFormatDate
If file.Name contains(goodFileName) Then
致:
为什么要使用
vb.net
标记?VBScript中不存在“函数”包含的
,并且没有函数会像您编写的那样工作。使用instr
。我正试图用vbscript编写这篇文章,我可以发誓我在这个网站上找到了其他几个使用contains和VBScriptReference的链接。我不确定contains是否是一个有效的函数,但如果是,你在file.Name和contains之间缺少了一个点。我对这一切都很陌生,contains可能不是一个有效的选项。我最后使用了left,它成功了,谢谢
If InStr(file.Name, goodFileName, vbTextCompare) > 0 Then