推荐:ASP Error对象的技巧在VBScript中,有一个On Error Resume Next语句,它使脚本解释器忽略运行期错误并继续脚本代码的执行。接着该脚本可以检查Err.Number属性的值,判别是否出现了错误。如果出现错误,返回一个非零值。在ASP 3.0中,也可以使用On Error Goto 0“转回到”缺省的
- '========================
- '文件1
- 'Pack.asp
- '更改 Cpathname 这一变量
- '将在当前目录生成一个DATA.XML文件
- '将DATA.XML及文件2(install.asp)上传至WEB根目录
- '运行install.asp解包
- '手动删除以上两个文件
- '========================
- <%OptionExplicit%>
- <%OnErrorResumeNext%>
- <%
- Server.ScriptTimeout=99999999
- dimCpathname
- dimstartime,endtime
- '在此更改要打包文件夹的路径
- Cpathname=F:WEBsymr
- startime=timer()
- functionbianli(path)
- dimdoc
- dimfso'fso对象
- dimobjFolder'文件夹对象
- dimobjSubFolders'子文件夹集合
- dimobjSubFolder'子文件夹对象
- dimobjFiles'文件集合
- dimobjFile'文件对象
- dimobjStream
- dimpathname,TextStream,pp,Xfolder,Xfpath,Xfile,Xpath,Xstream
- setfso=server.CreateObject(scripting.filesystemobject)
- setobjFolder=fso.GetFolder(path)'创建文件夹对象
- Response.Writepath
- Response.flush
- Setdoc=Server.CreateObject(MSxml2.DOMDocument)
- doc.loadServer.MapPath(data.xml)
- doc.async=false
- '写入每个文件夹路径
- setXfolder=doc.SelectSingleNode(//z-blog).AppendChild(doc.CreateElement(folder))
- SetXfpath=Xfolder.AppendChild(doc.CreateElement(path))
- Xfpath.text=replace(path,Cpathname,)
- setobjFiles=objFolder.Files
- foreachobjFileinobjFiles
- Response.Write
- ---
- pp=path&&objFile.name
- Response.Writepp&
- Response.flush
- '================================================
- '写入文件的路径及文件内容
- setXfile=doc.SelectSingleNode(//z-blog).AppendChild(doc.CreateElement(file))
- SetXpath=Xfile.AppendChild(doc.CreateElement(path))
- Xpath.text=replace(pp,Cpathname,)
- '创建文件流读入文件内容,并写入XML文件中
- SetobjStream=Server.CreateObject(ADODB.Stream)
- objStream.Type=1
- objStream.Open()
- objStream.LoadFromFile(pp)
- objStream.position=0
- SetXstream=Xfile.AppendChild(doc.CreateElement(stream))
- Xstream.SetAttributexmlns:dt,urn:schemas-microsoft-com:datatypes
- '文件内容采用二制方式存放
- Xstream.dataType=bin.base64
- Xstream.nodeTypedValue=objStream.Read()
- setobjStream=nothing
- setXpath=nothing
- setXstream=nothing
- setXfile=nothing
- '================================================
- next
- Response.Write<p>
- doc.saveserver.mappath(data.xml)
- setXfpath=nothing
- setXfolder=nothing
- setdoc=nothing
- '创建的子文件夹对象
- setobjSubFolders=objFolder.Subfolders
- '调用递归遍历子文件夹
- foreachobjSubFolderinobjSubFolders
- pathpathname=path++objSubFolder.name
- bianli(pathname)
- next
- setobjFolder=nothing
- setobjSubFolders=nothing
- setfso=nothing
- endfunction
- dimdoc,objPI
- '创建一个空的XML文件,为写入文件作准备
- Setdoc=Server.CreateObject(MSxml2.DOMDocument)
- doc.async=false
- setobjPI=doc.createProcessingInstruction(xml,version='1.0'encoding='UTF-8')
- doc.insertBeforeobjPI,doc.childNodes(0)
- doc.appendChild(doc.CreateElement(z-blog))
- doc.saveserver.mappath(data.xml)
- setobjPI=nothing
- setdoc=nothing
- bianli(Cpathname)
- endtime=timer()
- %>
- 页面执行时间:<%=FormatNumber((endtime-startime),3)%>秒
- '=================================
- '文件2
- 'install.asp
- '此文件改自z-blog安装文件
- '=================================
- <%@CODEPAGE=65001%>
- <%OptionExplicit%>
- <%OnErrorResumeNext%>
- <%Response.Charset=UTF-8%>
- <html>
- <head>
- <title>文件解包程序</title>
- </head>
- <body>
- <textareaname=contentcols=90rows=20style=border:0px;overflow:auto;border-width:0px;width:100%;background-color:#E8F3FF;scrolling=auto>
- <%
- DimstrLocalPath
- '得到当前文件夹的物理路径
- strLocalPath=Left(Request.ServerVariables(PATH_TRANSLATED),InStrRev(Request.ServerVariables(PATH_TRANSLATED),))
- DimstrDbPath
- DimobjXmlFile
- DimobjNodeList
- DimobjFSO
- DimobjStream
- Dimi,j
- SetobjXmlFile=Server.CreateObject(Microsoft.XMLDOM)
- objXmlFile.load(Server.MapPath(data.xml))
- IfobjXmlFile.readyState=4Then
- IfobjXmlFile.parseError.errorCode=0Then
- SetobjNodeList=objXmlFile.documentElement.selectNodes(//folder/path)
- SetobjFSO=CreateObject(Scripting.FileSystemObject)
- j=objNodeList.length-1
- Fori=0Toj
- IfobjFSO.FolderExists(strLocalPath&objNodeList(i).text)=FalseThen
- objFSO.CreateFolder(strLocalPath&objNodeList(i).text)
- EndIf
- Response.Write创建目录&objNodeList(i).text&vbCrlf
- Response.Flush
- Next
- SetobjNodeList=objXmlFile.documentElement.selectNodes(//file/path)
- j=objNodeList.length-1
- Fori=0Toj
- SetobjStream=CreateObject(ADODB.Stream)
- WithobjStream
- .Type=1
- .Open
- .WriteobjNodeList(i).nextSibling.nodeTypedvalue
- .SaveToFilestrLocalPath&objNodeList(i).text,2
- Response.Write释放文件&objNodeList(i).text&vbCrlf
- Response.Flush
- .Close
- EndWith
- SetobjStream=Nothing
- Next
- EndIf
- EndIf
- %>
- </textarea>
- <%response.write<script>alert('文件解包完毕!');</script>%>
分享:ASP开发中有用的函数(function)集合(1)ASP开发中有用的function集合,挺有用处的!希望大家保留! % '************************************* '防止外部提交 '************************************* function ChkPost() dim server_v1,server_v2 chkpost=false server_v1=Cstr(Request.ServerVari