Date 用于检查日期和扩展名的Vbs脚本

Date 用于检查日期和扩展名的Vbs脚本,date,vbscript,file-extension,Date,Vbscript,File Extension,嗨,我不能得到下面的脚本我的工作,以拿起文件的扩展名,有任何可以帮助我指出我哪里出了错 dim fileSystem, folder, file dim path dim count : count = 0 path = "C:\temp" Set fileSystem = CreateObject("Scripting.FileSystemObject") Set folder = fileSystem.GetFolder(path) for each file in folder.

嗨,我不能得到下面的脚本我的工作,以拿起文件的扩展名,有任何可以帮助我指出我哪里出了错

dim fileSystem, folder, file 
dim path
dim count : count = 0
path = "C:\temp" 

Set fileSystem = CreateObject("Scripting.FileSystemObject") 
Set folder = fileSystem.GetFolder(path)

for each file in folder.Files     
    if file.DateLastModified > dateadd("h", -24, Now) & File.name = "txt" then 

count = count + 1

end if
Next

if count < 4 then

Set WshShell = WScript.CreateObject("WScript.Shell")
strcommand = "eventcreate /T ERROR /ID 666 /L Application /SO BESROffsite /D " & _  
Chr(34) & count & " Files found please check offsite copy " & Chr(34)  
WshShell.Run strcommand
wScript.Quit ( 1001 )

Else

Set WshShell = WScript.CreateObject("WScript.Shell")
strcommand = "eventcreate /T Information /ID 666 /L Application /SO BESROffsite /D " & _  
Chr(34) & count & " Files found offsite is working fine " & Chr(34)  
WshShell.Run strcommand
wScript.Quit ( 0 )
End if
dim文件系统、文件夹、文件
幽径
dim计数:计数=0
path=“C:\temp”
设置fileSystem=CreateObject(“Scripting.FileSystemObject”)
Set folder=fileSystem.GetFolder(路径)
对于文件夹.Files中的每个文件
如果file.DateLastModified>dateadd(“h”、-24,Now)&file.name=“txt”,则
计数=计数+1
如果结束
下一个
如果计数小于4,则
设置WshShell=WScript.CreateObject(“WScript.Shell”)
strcommand=“eventcreate/T ERROR/ID 666/L Application/SO besrofsite/D”和
Chr(34)&计数和“找到的文件请检查场外副本”&Chr(34)
WshShell。运行strcommand
wScript.Quit(1001)
其他的
设置WshShell=WScript.CreateObject(“WScript.Shell”)
strcommand=“eventcreate/T Information/ID 666/L Application/SO besrofsite/D”和
Chr(34)&计数&“在场外发现的文件工作正常”&Chr(34)
WshShell。运行strcommand
wScript.Quit(0)
如果结束

文件。name
是包含扩展名的全名,用于测试扩展名

if ... fileSystem.getExtensionName(file.name) = "txt" then

您还需要逻辑
而不是按位连接
&

Alex的答案是您想要的答案,但仅供参考,如果您只使用vbs和字符串文件名,而不使用filesystemobject集合,则可以通过以下方式实现相同的效果:

Right(strFilename, Len(strFilename) - Instrrev(strFilename, "."))

这实际上是找到文件名中最后一个“.”的位置,从文件名的长度中去掉它,然后给出从右边开始相等的字符数。这可以稍微修改一下,使用“Mid”命令而不是“Right”,但我认为在这种情况下,这并不重要。

我在事件日志中获得了它应该做的信息,但它没有用.txt来提取文件,它只是说找到了0个文件
File.neme
拼写错误,这可能就够了吗?那只是我在这里的输入错误:(我在这里更正一下,谢谢你的款待:)这方面仍然很新,但进展缓慢。@Alex-+1.5,因为我抓住了&-0.5表示将串联误认为按位和。