VB获取文件大小问题?20分

来源:百度知道 编辑:UC知道 时间:2024/05/01 07:09:31
我想用VB来获取一个要下载的文件大小,怎么做!不是本地文件是要下载的网址文件!

Private Sub Command1_Click()
fname = "http://zhidao.baidu.com/question/104643911.html" '包含网络路径的下载文件
If Trim(fname) <> "" Then
Set xml = CreateObject("MSXML2.XMLHTTP")
xml.open "GET", fname, False
xml.send
header = xml.GetAllResponseHeaders
Print header
Set xml = Nothing
n = InStr(LCase(header), LCase("Content-Length:"))
n = n + Len("Content-Length:")
m = InStr(n + 1, header, vbCrLf)
If n > 0 Then
Print "文件长度:" & Mid(header, n, m - n)
End If
End If
End Sub

HTTP协议头部的Content-Length的值就是请求的文件的大小。

有专门的下载控件。没有你想的这么麻烦的。

百度下更详细哦!