捕捉并保存ASP运行错误的函数代码(2)


.open
.loadfromfile(server.MapPath(path))
tmp = .readtext()
end with
stream.close : set stream = nothing
file_read = tmp
end function
'函数:保存字符串到文件
function file_save(str,path,model)
if model<>0 and model<>1 then model=1
if model=0 and file_exists(path) then file_save=true : exit function
dim stream : set stream = server.CreateObject("ADODB.Stream")
with stream
.type = 2 '文本类型
.charset = "gb2312"
.open
.writetext str
.savetofile(server.MapPath(path)),model+1
end with
stream.close : set stream = nothing
file_save = file_exists(path)
end function
'函数:检测文件/文件夹是否存在
function file_exists(path)
dim tmp : tmp = false
dim fso : set fso = server.CreateObject("Scripting.FilesyStemObject")
if fso.fileexists(server.MapPath(path)) then tmp = true
if fso.folderexists(server.MapPath(path)) then tmp = true
set fso = nothing
file_exists = tmp
end function
%>