Files in ASP get file size

xiaoxiao2021-03-06  96

The following function is a function of obtaining a file size, and the implementation is as follows:

<%

'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")

%>