以下函数是获得文件大小的函数,具体实现如下:
<%
' Company: Sabra Inc
' Author: Dave Hoffenberg
' Function: Retrieves file size(K) of any file name passed to it.
' Freeware
Function ShowFileSize(filespec)
file = Server.MapPath(filespec)
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
Set f = fso.GetFile(file)
intSizeB = f.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
ShowFileSize = intSizeK & "k"
Else
ShowFileSize = "File Doesn't Exist"
End If
Set fso = Nothing
End Function
response.write ShowFileSize("test.txt")
%>
<%
' Company: Sabra Inc
' Author: Dave Hoffenberg
' Function: Retrieves file size(K) of any file name passed to it.
' Freeware
Function ShowFileSize(filespec)
file = Server.MapPath(filespec)
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(file) Then
Set f = fso.GetFile(file)
intSizeB = f.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
ShowFileSize = intSizeK & "k"
Else
ShowFileSize = "File Doesn't Exist"
End If
Set fso = Nothing
End Function
response.write ShowFileSize("test.txt")
%>
博客展示了一个用ASP实现的获取文件大小的函数。通过Server.MapPath获取文件路径,利用Scripting.FileSystemObject判断文件是否存在,若存在则计算文件大小(以K为单位),最后输出结果,还给出了调用示例。
404





