推薦: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