Recommended: Tips for ASP Error Objects In VBScript, there is an On Error Resume Next statement that causes the script interpreter to ignore runtime errors and continue execution of the script code. Then the script can check the value of the Err.Number property to determine whether an error occurred. If an error occurs, a non-zero value is returned. In ASP 3.0, you can also use On Error Goto 0 to "turn back to" the default
- '=================================
- 'File 1
- 'Pack.asp
- 'Change Cpathname this variable
- 'A DATA.XML file will be generated in the current directory
- 'Upload DATA.XML and file 2 (install.asp) to WEB root directory
- 'Run install.asp unpacking
- 'Manually delete the above two files
- '=================================
- <%OptionExplicit%>
- <%OnErrorResumeNext%>
- <%
- Server.ScriptTimeout=99999999
- dimCpathname
- dimstartime, endtime
- 'Change the path to the folder to be packaged here
- Cpathname=F:WEBsymr
- starttime=timer()
- functionbianli(path)
- dimdoc
- dimfso'fso object
- dimobjFolder' folder object
- dimobjSubFolders' subfolder collection
- dimobjSubFolder's subfolder object
- dimobjFiles' file collection
- dimobjFile' file object
- dimobjStream
- dimpathname,TextStream,pp,Xfolder,Xfpath,Xfile,Xpath,Xstream
- setfso=server.CreateObject(scripting.filesystemobject)
- setobjFolder=fso.GetFolder(path)'Create folder object
- Response.Writepath
- Response.flush
- Setdoc=Server.CreateObject(MSxml2.DOMDocument)
- doc.loadServer.MapPath(data.xml)
- doc.async=false
- 'Write to each folder path
- 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.Writep&
- Response.flush
- '==================================================================
- 'The path to the file and the file content
- setXfile=doc.SelectSingleNode(//z-blog).AppendChild(doc.CreateElement(file))
- SetXpath=Xfile.AppendChild(doc.CreateElement(path))
- Xpath.text=replace(pp,Cpathname,)
- 'Create a file stream to read the file content and write it to the XML file
- 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
- 'The file content is stored in two-system
- 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
- 'Created subfolder object
- setobjSubFolders=objFolder.Subfolders
- 'Call recursively traverse subfolders
- foreachobjSubFolderinobjSubFolders
- pathpathname=path++objSubFolder.name
- bianli(pathname)
- next
- setobjFolder=nothing
- setobjSubFolders=nothing
- setfso=nothing
- endfunction
- dimdoc,objPI
- 'Create an empty XML file to prepare for writing to the file
- 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()
- %>
- Page execution time: <%=FormatNumber((endtime-startime), 3)%> seconds
- '=============================================
- 'File 2
- 'install.asp
- 'This file is changed from the z-blog installation file
- '=============================================
- <%@CODEPAGE=65001%>
- <%OptionExplicit%>
- <%OnErrorResumeNext%>
- <%Response.Charset=UTF-8%>
- <html>
- <head>
- <title>File Unpacking Program</title>
- </head>
- <body>
- <textarename=contentcols=90rows=20style=border:0px;overflow:auto;border-width:0px;width:100%;background-color:#E8F3FF;scrolling=auto>
- <%
- DimstrLocalPath
- 'Get the physical path to the current folder
- 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.WriteCreate Directory&objNodeList(i).text&vbCrlf
- Response.Flush
- Next
- SetobjNodeList=objXmlFile.documentElement.selectNodes(//file/path)
- j=objNodeList.length-1
- Fori=0Toj
- SetobjStream=CreateObject(ADODB.Stream)
- WithoutbjStream
- .Type=1
- .Open
- .WriteobjNodeList(i).nextSibling.nodeTypedvalue
- .SaveToFilestrLocalPath&objNodeList(i).text,2
- Response.Write Release File &objNodeList(i).text&vbCrlf
- Response.Flush
- .Close
- EndWith
- SetobjStream=Nothing
- Next
- EndIf
- EndIf
- %>
- </textarea>
- <%response.write<script>alert('File Unpacked Complete!');</script>%>
Share: Useful collection of functions in ASP development (1) A collection of useful functions in ASP development is quite useful! I hope everyone keeps it! % '****************************************************** 'Prevent external submission'****************************************** function ChkPost() dim server_v1,server_v2 chkpost=false server_v1=Cstr(Request.ServerVari