标题: 求助. vbs多项判断出错!
[打印本页]
作者: ajon911
时间: 2009-9-15 00:17
标题: 求助. vbs多项判断出错!
判断网络文件是否存在出错!
以下vbs都报告"不存在",如何让判断正确跳转执行?(正确应该报告"存在"的,如果把用于判断"d:\123.txt"文件修改的部分去掉就能正确报告文件"存在")
On Error Resume Next
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("d:\123.txt")
md =DateValue(f.DateLastModified)
nd=date
if md<>nd then
url="http://www.baidu.com/img/baidu_logo.gif"
Set xmlHTTP=createobject("Microsoft.XMLHTTP")
xmlhttp.open "GET", URL, false
xmlhttp.send
if err.number <> 0 then
flagText = "google.com"
else
flagText = left(xmlhttp.responseText, 1703)
set regex = new RegExp
regEx.Global = True
regex.pattern = "^\s*"
flagText = regex.replace(flagText, "")
regex.pattern = "^<.*>"
flagText = regex.replace(flagText, "google.com")
flagText = left(flagText, 10)
end if
If flagText <> "google.com" Then
msgbox "存在"
else
msgbox "不存在"
end if
else
msgbox "今天修改过"
end if
作者: ywjco
时间: 2009-9-15 13:32
试过你的代码,没有问题。只是要先建立“d:\123.txt”这个文件。
***************************************
On Error Resume Next
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile("d:\123.txt")
md=DateValue(f.DateLastModified)
nd=date
if md<>nd then
url="http://www.baidu.com/img/baidu_logo.gif"
Set xmlHTTP=createobject("Microsoft.XMLHTTP")
xmlhttp.open "GET", URL, false
xmlhttp.send
if err.number <> 0 then
flagText = "google.com"
else
flagText = left(xmlhttp.responseText, 1703)
set regex = new RegExp
regEx.Global = True
regex.pattern = "^\s*"
flagText = regex.replace(flagText, "")
regex.pattern = "^<.*>"
flagText = regex.replace(flagText, "google.com")
flagText = left(flagText, 10)
end if
If flagText <> "google.com" Then
msgbox "存在"
else
msgbox "不存在"
end if
else
msgbox "今天修改过"
end if
********************************************
最后,还应加上两行:
Set fso = Nothing
Set f =Nothing