ASP利用XML打包指定文件夾 并上傳到WEB目錄中,自行解包_ASP教程
教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!
推薦:ASP Error對(duì)象的技巧在VBScript中,有一個(gè)On Error Resume Next語(yǔ)句,它使腳本解釋器忽略運(yùn)行期錯(cuò)誤并繼續(xù)腳本代碼的執(zhí)行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現(xiàn)了錯(cuò)誤。如果出現(xiàn)錯(cuò)誤,返回一個(gè)非零值。在ASP 3.0中,也可以使用On Error Goto 0“轉(zhuǎn)回到”缺省的
- '========================
- '文件1
- 'Pack.asp
- '更改 Cpathname 這一變量
- '將在當(dāng)前目錄生成一個(gè)DATA.XML文件
- '將DATA.XML及文件2(install.asp)上傳至WEB根目錄
- '運(yùn)行install.asp解包
- '手動(dòng)刪除以上兩個(gè)文件
- '========================
- <% Option Explicit %>
- <% On Error Resume Next %>
- <%
- Server.ScriptTimeout=99999999
- dim Cpathname
- dim startime,endtime
- '在此更改要打包文件夾的路徑
- Cpathname = "F:WEBsymr"
- startime=timer()
- function bianli(path)
- dim doc
- dim fso 'fso對(duì)象
- dim objFolder '文件夾對(duì)象
- dim objSubFolders '子文件夾集合
- dim objSubFolder '子文件夾對(duì)象
- dim objFiles '文件集合
- dim objFile '文件對(duì)象
- dim objStream
- dim pathname,TextStream,pp,Xfolder,Xfpath,Xfile,Xpath,Xstream
- set fso=server.CreateObject("scripting.filesystemobject")
- set objFolder=fso.GetFolder(path)'創(chuàng)建文件夾對(duì)象
- Response.Write path
- Response.flush
- Set doc = Server.CreateObject("MSxml2.DOMDocument")
- doc.load Server.MapPath("data.xml")
- doc.async=false
- '寫入每個(gè)文件夾路徑
- set Xfolder = doc.SelectSingleNode("//z-blog").AppendChild(doc.CreateElement("folder"))
- Set Xfpath = Xfolder.AppendChild(doc.CreateElement("path"))
- Xfpath.text = replace(path,Cpathname,"")
- set objFiles=objFolder.Files
- for each objFile in objFiles
- Response.Write "
- ---"
- pp = path & "" & objFile.name
- Response.Write pp & "
- "
- Response.flush
- '================================================
- '寫入文件的路徑及文件內(nèi)容
- set Xfile = doc.SelectSingleNode("//z-blog").AppendChild(doc.CreateElement("file"))
- Set Xpath = Xfile.AppendChild(doc.CreateElement("path"))
- Xpath.text = replace(pp,Cpathname,"")
- '創(chuàng)建文件流讀入文件內(nèi)容,并寫入XML文件中
- Set objStream = Server.CreateObject("ADODB.Stream")
- objStream.Type = 1
- objStream.Open()
- objStream.LoadFromFile(pp)
- objStream.position = 0
- Set Xstream = Xfile.AppendChild(doc.CreateElement("stream"))
- Xstream.SetAttribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
- '文件內(nèi)容采用二制方式存放
- Xstream.dataType = "bin.base64"
- Xstream.nodeTypedValue = objStream.Read()
- set objStream=nothing
- set Xpath = nothing
- set Xstream = nothing
- set Xfile = nothing
- '================================================
- next
- Response.Write "<p>"
- doc.save server.mappath("data.xml")
- set Xfpath = nothing
- set Xfolder = nothing
- set doc = nothing
- '創(chuàng)建的子文件夾對(duì)象
- set objSubFolders=objFolder.Subfolders
- '調(diào)用遞歸遍歷子文件夾
- for each objSubFolder in objSubFolders
- pathpathname=path + "" + objSubFolder.name
- bianli(pathname)
- next
- set objFolder=nothing
- set objSubFolders=nothing
- set fso=nothing
- end function
- dim doc,objPI
- '創(chuàng)建一個(gè)空的XML文件,為寫入文件作準(zhǔn)備
- Set doc = Server.CreateObject("MSxml2.DOMDocument")
- doc.async=false
- set objPI = doc.createProcessingInstruction("xml","version='1.0' encoding='UTF-8'")
- doc.insertBefore objPI, doc.childNodes(0)
- doc.appendChild(doc.CreateElement("z-blog"))
- doc.save server.mappath("data.xml")
- set objPI = nothing
- set doc = nothing
- bianli(Cpathname)
- endtime=timer()
- %>
- 頁(yè)面執(zhí)行時(shí)間:<%=FormatNumber((endtime-startime),3)%>秒
- '=================================
- '文件2
- 'install.asp
- '此文件改自z-blog安裝文件
- '=================================
- <%@ CODEPAGE=65001 %>
- <% Option Explicit %>
- <% On Error Resume Next %>
- <% Response.Charset="UTF-8" %>
- <html>
- <head>
- <title>文件解包程序</title>
- </head>
- <body>
- <textarea name="content" cols="90" rows="20" style="border:0px;overflow:auto;border-width:0px;width:100%;background-color:#E8F3FF;" scrolling="auto">
- <%
- Dim strLocalPath
- '得到當(dāng)前文件夾的物理路徑
- strLocalPath=Left(Request.ServerVariables("PATH_TRANSLATED"),InStrRev(Request.ServerVariables("PATH_TRANSLATED"),""))
- Dim strDbPath
- Dim objXmlFile
- Dim objNodeList
- Dim objFSO
- Dim objStream
- Dim i,j
- Set objXmlFile = Server.CreateObject("Microsoft.XMLDOM")
- objXmlFile.load(Server.MapPath("data.xml"))
- If objXmlFile.readyState=4 Then
- If objXmlFile.parseError.errorCode = 0 Then
- Set objNodeList = objXmlFile.documentElement.selectNodes("//folder/path")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- j=objNodeList.length-1
- For i=0 To j
- If objFSO.FolderExists(strLocalPath & objNodeList(i).text)=False Then
- objFSO.CreateFolder(strLocalPath & objNodeList(i).text)
- End If
- Response.Write "創(chuàng)建目錄" & objNodeList(i).text & vbCrlf
- Response.Flush
- Next
- Set objNodeList = objXmlFile.documentElement.selectNodes("//file/path")
- j=objNodeList.length-1
- For i=0 To j
- Set objStream = CreateObject("ADODB.Stream")
- With objStream
- .Type = 1
- .Open
- .Write objNodeList(i).nextSibling.nodeTypedvalue
- .SaveToFile strLocalPath & objNodeList(i).text,2
- Response.Write "釋放文件" & objNodeList(i).text & vbCrlf
- Response.Flush
- .Close
- End With
- Set objStream = Nothing
- Next
- End If
- End If
- %>
- </textarea>
- <%response.write "<script>alert('文件解包完畢!');</script>"%>
分享:ASP開發(fā)中有用的函數(shù)(function)集合(1)ASP開發(fā)中有用的function集合,挺有用處的!希望大家保留! % '************************************* '防止外部提交 '************************************* function ChkPost() dim server_v1,server_v2 chkpost=false server_v1=Cstr(Request.ServerVari
相關(guān)ASP教程:
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫(kù)實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過(guò)濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁(yè)模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無(wú)組件分頁(yè)實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說(shuō)明:
ASP教程-ASP利用XML打包指定文件夾 并上傳到WEB目錄中,自行解包。