ASP根据自定义的目录名称生成目录,本函数使用FSO来实现,使用广泛,通过封装成函数后使用起来更方便了,特别适合用在生成HTML目录功能中。
<% Function MakeNewsDir(foldername) dim fso,f Set fso = Server.CreateObject("Scripting.FileSystemObject") Set f = fso.CreateFolder(foldername) MakeNewsDir = True Set fso = nothing End Function Function CreateHTMLPage(filename,FileData,C_mode) '生成文件 if C_mode=0 then '使用FSO生成 Dim fso,txt Set fso = CreateObject("Scripting.FileSystemObject") Filepath=Server.MapPath(filename) if CheckFile(filename) then fso.DeleteFile Filepath,True '防止续写 Set txt=fso.OpenTextFile(Filepath,8,True) txt.Write FileData txt.Close Set fso = nothing elseif C_mode=1 then '使用Stream生成 Dim viboStream On Error Resume Next Set viboStream = Server.createObject("ADODB.Stream") If Err.Number=-2147221005 Then Response.Write "<div align='center' style=""font-size:12px;font-family:Tahoma;"">不好意思,您的主机不支持ADODB.Stream,本程序无法运行!</div>" Err.Clear Response.End End If With viboStream .Type = 2 .Open .CharSet = "GB2312" .Position = objStream.Size .WriteText = FileData .SaveToFile Server.MapPath(filename),2 .Close End With Set viboStream = Nothing end if Response.Write "<div align='center' style=""font-size:12px;font-family:Tahoma;"">文件 <a href="""&filename&""" target=""_blank"" style=""font-weight: bold;color: #FF0000;"">"&filename&"</a> 已经生成完毕!...</div>" Response.Flush() End Function %>