中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-07-11 15:17
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 求助. vbs多项判断出错! 查看 864 回复 1
楼 主 求助. vbs多项判断出错! 发表于 2009-09-15 00:17 ·  中国 广东 东莞 电信
初级用户
积分 49
发帖 24
注册 2007-12-03 21:34
18年会员
UID 104583
性别 男
状态 离线
判断网络文件是否存在出错!
以下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
2 发表于 2009-09-15 13:32 ·  中国 广东 电信
初级用户
积分 31
发帖 17
注册 2007-10-31 22:38
18年会员
UID 101331
性别 男
状态 离线
试过你的代码,没有问题。只是要先建立“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
论坛跳转: