asp源码打包成xml的工具

2018-09-06 11:40

阅读:349

  下边这个存为Pack.asp,打包文件时运行
复制代码 代码如下:
<%@LANGUAGE=VBSCRIPTCODEPAGE=65001%>
<%OptionExplicit%>
<%OnErrorResumeNext%>
<%Response.Charset=UTF-8%>
<%Server.ScriptTimeout=99999999%>
<!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN
<htmlxmlns=
<head>
<metahttp-equiv=Content-Typecontent=text/html;charset=utf-8/>
<title>文件打包程序</title>
</head>

<body>
<%


DimZipPathDir,ZipPathFile
Dimstartime,endtime
在此更改要打包文件夹的路径
ZipPathDir=F:\
ZipPathFile=update.xml
IfRight(ZipPathDir,1)<>\ThenZipPathDir=ZipPathDir&\
开始打包
CreateXml(ZipPathFile)
遍历目录内的所有文件以及文件夹

SubLoadData(DirPath)
DimXmlDoc
Dimfsofso对象
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
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.SetAttributexmlns: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.0encoding=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=VBSCRIPTCODEPAGE=65001%>
<%OptionExplicit%>
<%OnErrorResumeNext%>
<%Response.Charset=UTF-8%>
<%Server.ScriptTimeout=99999999%>
<!DOCTYPEhtmlPUBLIC-//W3C//DTDXHTML1.0Transitional//EN
<htmlxmlns=
<head>
<metahttp-equiv=Content-Typecontent=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>


评论


亲,登录后才可以留言!