日期:2011-08-17 浏览次数:21325 次
<%
'欢迎与我交流和学习
'作者:幸福的子弹
'BLOG:http://mysheji.com/blog
'E-mail:zhaojiangang@gmail.com
'QQ:37294812
'-----------------------------------------------------------------------------
'开启容错机制
on error resume next
'功能,检测服务器是否支持指定组件
Function object_install(strclassstring)
on error resume next
object_install=false
dim xtestobj
set xtestobj=server.createobject(strclassstring)
if -2147221005 <> Err then object_install=true
set xtestobj=nothing
end function
if object_install("Scripting.FileSystemobject")=false then
Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>对不起,您的空间不支持FSO组件,请与管理员联系!</div>"
Response.End
end if
if object_install("adodb.stream")=false then
Response.Write "<div style='font-size:12px;color:#333;height:20px;line-height:20px;border:1px solid #DDCF8F;padding:6px;background:#FFFFED;font-family:verdana'>对不起,您的空间不支持adodb.stream功能,请与管理员联系!</div>"
Response.End
end if
'-----------------------------------------------------------------------------
'函数名称:ReadTextFile
'作用:利用AdoDb.Stream对象来读取文本文件
'参数:FileUrl文件相对路径,FileCharSet:文件编码
Function ReadFromTextFile (FileUrl,FileCharSet)'函数
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '指定或返回的数据类型,
stm.mode=3 '指定打开模式,现在为可以读写模式,类似于word的只读或锁定功能
stm.charset=FileCharSet
stm.open
stm.loadfromfile server.MapPath(FileUrl)
str=stm.readtext
ReadFromTextFile=str
End Function
'-----------------------------------------------------------------------------
'函数名称:WriteToTextFile
'作用:利用AdoDb.Stream对象来写入文本文件
sub WriteToTextFile(FileUrl,Str,FileCharSet) '方法
set stm=server.CreateObject("adodb.stream")
stm.Type=2
stm.mode=3
stm.charset=FileCharSet
stm.open
stm.WriteText str
stm.SaveToFile server.MapPath(FileUrl),2
stm.flush
End sub
'-----------------------------------------------------------------------------
'功能:自动创建文件夹
'创建一级或多级目录,可以创建不存在的根目录
'参数:要创建的目录名称,可以是多级
'返回逻辑值,True成功,False失败
'创建目录的根目录从当前目录开始
Function CreateMultiFolder(ByVal CFolder)
Dim objFSO,PhCreateFolder,CreateFolderArray,CreateFolder
Dim i,ii,CreateFolderSub,PhCreateFolderSub,BlInfo
BlInfo = False
CreateFolder = CFolder
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If Err Then
Err.Clear()
Exit Function
End If
CreateFolder = Replace(CreateFolder,"","/")
If Left(CreateFolder,1)="/" Then
CreateFolder = Right(CreateFolder,Len(CreateFolder)-1)
End If
If Right(CreateFolder,1)="/" Then
CreateFolder = Left(CreateFolder,Len(CreateFolder)-1)
End If
CreateFolderArray = Split(CreateFolder,"/")
For i = 0 to UBound(CreateFolderArray)
CreateFolderSub = ""
Fo