asp源码打包成xml的工具_ASP教程-查字典教程网
asp源码打包成xml的工具
asp源码打包成xml的工具
发布时间:2016-12-29 来源:查字典编辑
摘要:下边这个存为Pack.asp,打包文件时运行复制代码代码如下:文件打包程序下边这个存为Install.asp,安装XML打包文件时运行复制代...

下边这个存为Pack.asp,打包文件时运行

复制代码 代码如下:

<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>

<%OptionExplicit%>

<%OnErrorResumeNext%>

<%Response.Charset="UTF-8"%>

<%Server.ScriptTimeout=99999999%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<title>文件打包程序</title>

</head>

<body>

<%

DimZipPathDir,ZipPathFile

Dimstartime,endtime

'在此更改要打包文件夹的路径

ZipPathDir="F:www.yongfa365.com"'

ZipPathFile="update.xml"

IfRight(ZipPathDir,1)<>""ThenZipPathDir=ZipPathDir&""

'开始打包

CreateXml(ZipPathFile)

'遍历目录内的所有文件以及文件夹

SubLoadData(DirPath)

DimXmlDoc

Dimfso'fso对象

DimobjFolder'文件夹对象

DimobjSubFolders'子文件夹集合

DimobjSubFolder'子文件夹对象

DimobjFiles'文件集合

DimobjFile'文件对象

DimobjStream

Dimpathname,TextStream,pp,Xfolder,Xfpath,Xfile,Xpath,Xstream

DimPathNameStr

response.Write("=========="&DirPath&"==========<br>")

Setfso=server.CreateObject("scripting.filesystemobject")

SetobjFolder=fso.GetFolder(DirPath)'创建文件夹对象

Response.WriteDirPath

Response.flush

SetXmlDoc=Server.CreateObject("Microsoft.XMLDOM")

XmlDoc.loadServer.MapPath(ZipPathFile)

XmlDoc.async=False

'写入每个文件夹路径

SetXfolder=XmlDoc.SelectSingleNode("//root").AppendChild(XmlDoc.CreateElement("folder"))

SetXfpath=Xfolder.AppendChild(XmlDoc.CreateElement("path"))

Xfpath.text=Replace(DirPath,ZipPathDir,"")

SetobjFiles=objFolder.Files

ForEachobjFileinobjFiles

IfLCase(DirPath&objFile.Name)<>LCase(Request.ServerVariables("PATH_TRANSLATED"))Then

Response.Write"---<br/>"

PathNameStr=DirPath&""&objFile.Name

Response.WritePathNameStr&""

Response.flush

'================================================

'写入文件的路径及文件内容

SetXfile=XmlDoc.SelectSingleNode("//root").AppendChild(XmlDoc.CreateElement("file"))

SetXpath=Xfile.AppendChild(XmlDoc.CreateElement("path"))

Xpath.text=Replace(PathNameStr,ZipPathDir,"")

'创建文件流读入文件内容,并写入XML文件中

SetobjStream=Server.CreateObject("ADODB.Stream")

objStream.Type=1

objStream.Open()

objStream.LoadFromFile(PathNameStr)

objStream.position=0

SetXstream=Xfile.AppendChild(XmlDoc.CreateElement("stream"))

Xstream.SetAttribute"xmlns:dt","urn:schemas-microsoft-com:datatypes"

'文件内容采用二制方式存放

Xstream.dataType="bin.base64"

Xstream.nodeTypedValue=objStream.Read()

SetobjStream=Nothing

SetXpath=Nothing

SetXstream=Nothing

SetXfile=Nothing

'================================================

EndIf

Next

Response.Write"<p>"

XmlDoc.Save(Server.Mappath(ZipPathFile))

SetXfpath=Nothing

SetXfolder=Nothing

SetXmlDoc=Nothing

'创建的子文件夹对象

SetobjSubFolders=objFolder.SubFolders

'调用递归遍历子文件夹

ForEachobjSubFolderinobjSubFolders

pathname=DirPath&objSubFolder.Name&""

LoadData(pathname)

Next

SetobjFolder=Nothing

SetobjSubFolders=Nothing

Setfso=Nothing

EndSub

'创建一个空的XML文件,为写入文件作准备

SubCreateXml(FilePath)

'程序开始执行时间

startime=Timer()

DimXmlDoc,Root

SetXmlDoc=Server.CreateObject("Microsoft.XMLDOM")

XmlDoc.async=False

SetRoot=XmlDoc.createProcessingInstruction("xml","version='1.0'encoding='UTF-8'")

XmlDoc.appendChild(Root)

XmlDoc.appendChild(XmlDoc.CreateElement("root"))

XmlDoc.Save(Server.MapPath(FilePath))

SetRoot=Nothing

SetXmlDoc=Nothing

LoadData(ZipPathDir)

'程序结束时间

endtime=Timer()

response.Write("页面执行时间:"&FormatNumber((endtime-startime),3)&"秒")

EndSub

%>

</body>

</html>

下边这个存为Install.asp,安装XML打包文件时运行

复制代码 代码如下:

<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>

<%OptionExplicit%>

<%OnErrorResumeNext%>

<%Response.Charset="UTF-8"%>

<%Server.ScriptTimeout=99999999%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<head>

<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>

<title>文件解包程序</title>

</head>

<body>

<%

DimstrLocalPath

'得到当前文件夹的物理路径

strLocalPath=Left(Request.ServerVariables("PATH_TRANSLATED"),InStrRev(Request.ServerVariables("PATH_TRANSLATED"),""))

DimobjXmlFile

DimobjNodeList

DimobjFSO

DimobjStream

Dimi,j

SetobjXmlFile=Server.CreateObject("Microsoft.XMLDOM")

objXmlFile.load(Server.MapPath("update.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&"<br/>"

Response.Flush

Next

SetobjFSO=Nothing

SetobjNodeList=Nothing

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&"<br/>"

Response.Flush

.Close

EndWith

SetobjStream=Nothing

Next

SetobjNodeList=Nothing

EndIf

EndIf

SetobjXmlFile=Nothing

response.Write"文件解包完毕"

%>

</body>

</html>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新ASP教程学习
    热门ASP教程学习
    编程开发子分类