asp静态页生成类 FSO生成静态类
看到好东西怎么能不收藏呢,留下备用,呵呵~~
<%
'/*************************
'/ 属性设置说明
'/ foldename "文件夹名", 如果不设置,将自动生成[年月日]时间格式的文件夹名
'/ Filename "文件名"(含前后缀), 如果不设置,将自动生成[时分秒]时间格式的文件名,后缀为.html
'/ Htmlstr "生成的代码内容"
'/*************************
Class Htmlmaker
Private HtmlFolder,HtmlFilename,HtmlContent
Public property let foldename(str)
HtmlFolder=str
End property
Public property let Filename(str)
HtmlFilename=str
End property
Public property let Htmlstr(str)
HtmlContent=str
End property
'/*************************
'/ 文件名转换日期函数
'/有点繁索,直接用Right("0"&Year(now),2),省去了垒碓重复的判断语句!为保留作者代码的完整性,未做修改
'/*************************
Private Function Datename1(timestr)
dim s_year,s_month,s_day
s_year=year(timestr)
if len(s_year)=2 then s_year="20"&s_year
s_month=month(timestr)
if s_month<10 then s_month="0"&s_month
s_day=day(timestr)
if s_day<10 then s_day="0"&s_day
Datename1=s_year & s_month & s_day
End Function
Private Function Datename2(timestr)
dim s_hour,s_minute,s_ss
s_hour=hour(timestr)
if s_hour<10 then s_hour="0"&s_hour
s_minute=minute(timestr)
if s_minute<10 then s_minute="0"&s_minute
s_ss=second(timestr)
if s_ss<10 then s_ss="0"&s_ss
Datename2 = s_hour & s_minute & s_ss
End Function
'/*************************
'/ 初试化
'/*************************
Private Sub class_initialize()
HtmlFolder=Datename1(now)
HtmlFilename=Datename2(now)&".html"
HtmlContent=""
End Sub
Private Sub class_terminate()
End Sub
'/*************************
'/ Html文件生成
'/*************************
Public Sub Htmlmake()
On Error Resume Next
dim filepath,fso,fout
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(HtmlFolder) Then
Else
fso.CreateFolder(Server.MapPath(HtmlFolder))
End If
Set fout = fso.CreateTextFile(Server.MapPath(filepath),true)
fout.WriteLine HtmlContent
fout.close
End Sub
'/*************************
'/ Html文件删除
'/*************************
Public Sub Htmldel()
dim filepath,fso
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(Server.mappath(filepath))
Set fso = nothing
End Sub
End class
%>
示例演示:(MakeTest.asp)
<!--#i nclude file="Htmlmaker.asp" -->
<%
set html= new Htmlmaker
html.foldename = Year(now)&"/"&Right("0"&Month(now),2)&"/"&Right("0"&day(now),2)
html.Filename = ""&now()&".shtml"
html.Htmlstr = "<html><head></head><body>"&now()&"</body></html>"
html.Htmlmake
if err then
Response.Write "Error!"
else
Response.Write "OK"
end if
set myhtml=nothing
%>
看到好东西怎么能不收藏呢,留下备用,呵呵~~
<%
'/*************************
'/ 属性设置说明
'/ foldename "文件夹名", 如果不设置,将自动生成[年月日]时间格式的文件夹名
'/ Filename "文件名"(含前后缀), 如果不设置,将自动生成[时分秒]时间格式的文件名,后缀为.html
'/ Htmlstr "生成的代码内容"
'/*************************
Class Htmlmaker
Private HtmlFolder,HtmlFilename,HtmlContent
Public property let foldename(str)
HtmlFolder=str
End property
Public property let Filename(str)
HtmlFilename=str
End property
Public property let Htmlstr(str)
HtmlContent=str
End property
'/*************************
'/ 文件名转换日期函数
'/有点繁索,直接用Right("0"&Year(now),2),省去了垒碓重复的判断语句!为保留作者代码的完整性,未做修改
'/*************************
Private Function Datename1(timestr)
dim s_year,s_month,s_day
s_year=year(timestr)
if len(s_year)=2 then s_year="20"&s_year
s_month=month(timestr)
if s_month<10 then s_month="0"&s_month
s_day=day(timestr)
if s_day<10 then s_day="0"&s_day
Datename1=s_year & s_month & s_day
End Function
Private Function Datename2(timestr)
dim s_hour,s_minute,s_ss
s_hour=hour(timestr)
if s_hour<10 then s_hour="0"&s_hour
s_minute=minute(timestr)
if s_minute<10 then s_minute="0"&s_minute
s_ss=second(timestr)
if s_ss<10 then s_ss="0"&s_ss
Datename2 = s_hour & s_minute & s_ss
End Function
'/*************************
'/ 初试化
'/*************************
Private Sub class_initialize()
HtmlFolder=Datename1(now)
HtmlFilename=Datename2(now)&".html"
HtmlContent=""
End Sub
Private Sub class_terminate()
End Sub
'/*************************
'/ Html文件生成
'/*************************
Public Sub Htmlmake()
On Error Resume Next
dim filepath,fso,fout
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = Server.CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(HtmlFolder) Then
Else
fso.CreateFolder(Server.MapPath(HtmlFolder))
End If
Set fout = fso.CreateTextFile(Server.MapPath(filepath),true)
fout.WriteLine HtmlContent
fout.close
End Sub
'/*************************
'/ Html文件删除
'/*************************
Public Sub Htmldel()
dim filepath,fso
filepath = HtmlFolder&"/"&HtmlFilename
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile(Server.mappath(filepath))
Set fso = nothing
End Sub
End class
%>
示例演示:(MakeTest.asp)
<!--#i nclude file="Htmlmaker.asp" -->
<%
set html= new Htmlmaker
html.foldename = Year(now)&"/"&Right("0"&Month(now),2)&"/"&Right("0"&day(now),2)
html.Filename = ""&now()&".shtml"
html.Htmlstr = "<html><head></head><body>"&now()&"</body></html>"
html.Htmlmake
if err then
Response.Write "Error!"
else
Response.Write "OK"
end if
set myhtml=nothing
%>