您的位置:首页 > 理论基础 > 计算机网络

VB 检测网络文件的修改时间

2010-10-14 20:31 155 查看
用VB 检测一个网络的DAT或者EXE文件的修改时间或者MD5码之类的,主要就是想知道这个网络文件有没有改变,请不要说下载下来在检测,那个文件几G 根本不行!只要可以达到知道网络那个文件是不是有修改了就行了

Private Sub Form_Load()
url = "http://zhidao.baidu.com/question/159150923.html"
url = "http://www.baidu.com/img/baidu_logo.gif"
Set XMLHTTP = CreateObject("Microsoft.XMLHTTP")
XMLHTTP.Open "HEAD", Trim(url), False
XMLHTTP.send
MsgBox XMLHTTP.getAllResponseHeaders
If InStr(1, XMLHTTP.getAllResponseHeaders, "Last-Modified") Then
MsgBox "文件最后更新时间:" & GMT_Trans(XMLHTTP.getResponseHeader("Last-Modified"))
End If
End Sub

Function GMT_Trans(s_time)

str_time = Mid(s_time, InStr(1, s_time, ",") + 1, InStr(1, s_time, "GMT") - InStr(1, s_time, ",") - 1)
str_time = Trim(str_time)
a_strtime = Split(str_time, " ", -1, 1)
s_month = a_strtime(1)
Select Case s_month
Case "Jan"
s_month = "01"
Case "Feb"
s_month = "02"
Case "Mar"
s_month = "03"
Case "Apr"
s_month = "04"
Case "May"
s_month = "05"
Case "Jun"
s_month = "06"
Case "Jul"
s_month = "07"
Case "Aug"
s_month = "08"
Case "Sep"
s_month = "09"
Case "Oct"
s_month = "10"
Case "Nov"
s_month = "11"
Case "Dec"
s_month = "12"
Case Else
s_month = "01"
End Select
GMT_Trans = a_strtime(2) & "-" & s_month & "-" & a_strtime(0) & " " & a_strtime(3)
End Function


http://zhidao.baidu.com/question/159150923.html

直接使用以下模块

Function GetUrlTime(Url As String)
On Error Resume Next
Set XMLHTTP = CreateObject("Microsoft.XMLHTTP")
XMLHTTP.Open "HEAD", Trim(Url), False
XMLHTTP.send
If InStr(1, XMLHTTP.getAllResponseHeaders, "Last-Modified") = 0 Then
MsgBox "获取文件的修改日期失败!", 16
GetUrlTime = ""
Else
GetUrlTime = GMT_Trans(XMLHTTP.getResponseHeader("Last-Modified"))
End If
End Function

Function GMT_Trans(s_time)
str_time = Mid(s_time, InStr(1, s_time, ",") + 1, InStr(1, s_time, "GMT") - InStr(1, s_time, ",") - 1)
str_time = Trim(str_time)
a_strtime = Split(str_time, " ", -1, 1)
s_month = a_strtime(1)
Select Case s_month
Case "Jan"
s_month = "01"
Case "Feb"
s_month = "02"
Case "Mar"
s_month = "03"
Case "Apr"
s_month = "04"
Case "May"
s_month = "05"
Case "Jun"
s_month = "06"
Case "Jul"
s_month = "07"
Case "Aug"
s_month = "08"
Case "Sep"
s_month = "09"
Case "Oct"
s_month = "10"
Case "Nov"
s_month = "11"
Case "Dec"
s_month = "12"
Case Else
s_month = "01"
End Select
GMT_Trans = a_strtime(2) & "-" & s_month & "-" & a_strtime(0) & " " & a_strtime(3)
End Function
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: