天天看点

ASP如何获取文件和目录空间大小

一、获取文件大小
 
<%
FPath=server.mappath("1.htm") '本地文件地址
Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFile(FPath)
size=f.size
response.write "文件名称:"&f.name"<br>"
if size>="1000" then
   response.write "文件大小:"&f.size/1024&"KB<br>"
else
   response.write "文件大小:"&f.size/(1024*1024)&"MB<br>"
end if
response.write "创建时间:"&f.DateCreated
%> 

 
二、获取文件夹大小
Function FunFileSize()
  dim FSO,dir,strSize
  set FSO = server.CreateObject("Scripting.FileSystemObject")
  set dir = FSO.GetFolder(Server.MapPath("../"))
  strSize = cSize(dir.Size)
  Set dir = Nothing
  Set FSO = Nothing
  FunFileSize = strSize
End Function      

继续阅读