asp源码打包成xml的工具
程序员文章站
2022-04-14 19:19:24
下边这个存为pack.asp,打包文件时运行 复制代码 代码如下:<%@language="vbscript" codepage="65001"%>&...
下边这个存为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>
<%
dim zippathdir, zippathfile
dim startime, endtime
'在此更改要打包文件夹的路径
zippathdir ="f:\www.yongfa365.com"'
zippathfile ="update.xml"
if right(zippathdir,1)<>"\"then zippathdir = zippathdir&"\"
'开始打包
createxml(zippathfile)
'遍历目录内的所有文件以及文件夹
sub loaddata(dirpath)
dim xmldoc
dim fso 'fso对象
dim objfolder '文件夹对象
dim objsubfolders '子文件夹集合
dim objsubfolder '子文件夹对象
dim objfiles '文件集合
dim objfile '文件对象
dim objstream
dim pathname, textstream, pp, xfolder, xfpath, xfile, xpath, xstream
dim pathnamestr
response.write("=========="&dirpath&"==========<br>")
set fso = server.createobject("scripting.filesystemobject")
set objfolder = fso.getfolder(dirpath)'创建文件夹对象
response.write dirpath
response.flush
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.load server.mappath(zippathfile)
xmldoc.async =false
'写入每个文件夹路径
set xfolder = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("folder"))
set xfpath = xfolder.appendchild(xmldoc.createelement("path"))
xfpath.text = replace(dirpath, zippathdir,"")
set objfiles = objfolder.files
foreach objfile in objfiles
if lcase(dirpath & objfile.name)<> lcase(request.servervariables("path_translated"))then
response.write "---<br/>"
pathnamestr = dirpath &""& objfile.name
response.write pathnamestr &""
response.flush
'================================================
'写入文件的路径及文件内容
set xfile = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("file"))
set xpath = xfile.appendchild(xmldoc.createelement("path"))
xpath.text = replace(pathnamestr, zippathdir,"")
'创建文件流读入文件内容,并写入xml文件中
set objstream = server.createobject("adodb.stream")
objstream.type=1
objstream.open()
objstream.loadfromfile(pathnamestr)
objstream.position =0
set xstream = xfile.appendchild(xmldoc.createelement("stream"))
xstream.setattribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
'文件内容采用二制方式存放
xstream.datatype ="bin.base64"
xstream.nodetypedvalue = objstream.read()
set objstream =nothing
set xpath =nothing
set xstream =nothing
set xfile =nothing
'================================================
endif
next
response.write "<p>"
xmldoc.save(server.mappath(zippathfile))
set xfpath =nothing
set xfolder =nothing
set xmldoc =nothing
'创建的子文件夹对象
set objsubfolders = objfolder.subfolders
'调用递归遍历子文件夹
foreach objsubfolder in objsubfolders
pathname = dirpath & objsubfolder.name &"\"
loaddata(pathname)
next
set objfolder =nothing
set objsubfolders =nothing
set fso =nothing
endsub
'创建一个空的xml文件,为写入文件作准备
sub createxml(filepath)
'程序开始执行时间
startime = timer()
dim xmldoc, root
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.async =false
set root = xmldoc.createprocessinginstruction("xml","version='1.0' encoding='utf-8'")
xmldoc.appendchild(root)
xmldoc.appendchild(xmldoc.createelement("root"))
xmldoc.save(server.mappath(filepath))
set root =nothing
set xmldoc =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>
<%
dim strlocalpath
'得到当前文件夹的物理路径
strlocalpath = left(request.servervariables("path_translated"), instrrev(request.servervariables("path_translated"),"\"))
dim objxmlfile
dim objnodelist
dim objfso
dim objstream
dim i, j
set objxmlfile = server.createobject("microsoft.xmldom")
objxmlfile.load(server.mappath("update.xml"))
if objxmlfile.readystate =4then
if objxmlfile.parseerror.errorcode =0then
set objnodelist = objxmlfile.documentelement.selectnodes("//folder/path")
set objfso = createobject("scripting.filesystemobject")
j = objnodelist.length -1
for i =0to j
if objfso.folderexists(strlocalpath & objnodelist(i).text)=falsethen
objfso.createfolder(strlocalpath & objnodelist(i).text)
endif
response.write "创建目录"& objnodelist(i).text &"<br/>"
response.flush
next
set objfso =nothing
set objnodelist =nothing
set objnodelist = objxmlfile.documentelement.selectnodes("//file/path")
j = objnodelist.length -1
for i =0to 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 &"<br/>"
response.flush
.close
endwith
set objstream =nothing
next
set objnodelist =nothing
endif
endif
set objxmlfile =nothing
response.write "文件解包完毕"
%>
</body>
</html>
复制代码 代码如下:
<%@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>
<%
dim zippathdir, zippathfile
dim startime, endtime
'在此更改要打包文件夹的路径
zippathdir ="f:\www.yongfa365.com"'
zippathfile ="update.xml"
if right(zippathdir,1)<>"\"then zippathdir = zippathdir&"\"
'开始打包
createxml(zippathfile)
'遍历目录内的所有文件以及文件夹
sub loaddata(dirpath)
dim xmldoc
dim fso 'fso对象
dim objfolder '文件夹对象
dim objsubfolders '子文件夹集合
dim objsubfolder '子文件夹对象
dim objfiles '文件集合
dim objfile '文件对象
dim objstream
dim pathname, textstream, pp, xfolder, xfpath, xfile, xpath, xstream
dim pathnamestr
response.write("=========="&dirpath&"==========<br>")
set fso = server.createobject("scripting.filesystemobject")
set objfolder = fso.getfolder(dirpath)'创建文件夹对象
response.write dirpath
response.flush
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.load server.mappath(zippathfile)
xmldoc.async =false
'写入每个文件夹路径
set xfolder = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("folder"))
set xfpath = xfolder.appendchild(xmldoc.createelement("path"))
xfpath.text = replace(dirpath, zippathdir,"")
set objfiles = objfolder.files
foreach objfile in objfiles
if lcase(dirpath & objfile.name)<> lcase(request.servervariables("path_translated"))then
response.write "---<br/>"
pathnamestr = dirpath &""& objfile.name
response.write pathnamestr &""
response.flush
'================================================
'写入文件的路径及文件内容
set xfile = xmldoc.selectsinglenode("//root").appendchild(xmldoc.createelement("file"))
set xpath = xfile.appendchild(xmldoc.createelement("path"))
xpath.text = replace(pathnamestr, zippathdir,"")
'创建文件流读入文件内容,并写入xml文件中
set objstream = server.createobject("adodb.stream")
objstream.type=1
objstream.open()
objstream.loadfromfile(pathnamestr)
objstream.position =0
set xstream = xfile.appendchild(xmldoc.createelement("stream"))
xstream.setattribute "xmlns:dt","urn:schemas-microsoft-com:datatypes"
'文件内容采用二制方式存放
xstream.datatype ="bin.base64"
xstream.nodetypedvalue = objstream.read()
set objstream =nothing
set xpath =nothing
set xstream =nothing
set xfile =nothing
'================================================
endif
next
response.write "<p>"
xmldoc.save(server.mappath(zippathfile))
set xfpath =nothing
set xfolder =nothing
set xmldoc =nothing
'创建的子文件夹对象
set objsubfolders = objfolder.subfolders
'调用递归遍历子文件夹
foreach objsubfolder in objsubfolders
pathname = dirpath & objsubfolder.name &"\"
loaddata(pathname)
next
set objfolder =nothing
set objsubfolders =nothing
set fso =nothing
endsub
'创建一个空的xml文件,为写入文件作准备
sub createxml(filepath)
'程序开始执行时间
startime = timer()
dim xmldoc, root
set xmldoc = server.createobject("microsoft.xmldom")
xmldoc.async =false
set root = xmldoc.createprocessinginstruction("xml","version='1.0' encoding='utf-8'")
xmldoc.appendchild(root)
xmldoc.appendchild(xmldoc.createelement("root"))
xmldoc.save(server.mappath(filepath))
set root =nothing
set xmldoc =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>
<%
dim strlocalpath
'得到当前文件夹的物理路径
strlocalpath = left(request.servervariables("path_translated"), instrrev(request.servervariables("path_translated"),"\"))
dim objxmlfile
dim objnodelist
dim objfso
dim objstream
dim i, j
set objxmlfile = server.createobject("microsoft.xmldom")
objxmlfile.load(server.mappath("update.xml"))
if objxmlfile.readystate =4then
if objxmlfile.parseerror.errorcode =0then
set objnodelist = objxmlfile.documentelement.selectnodes("//folder/path")
set objfso = createobject("scripting.filesystemobject")
j = objnodelist.length -1
for i =0to j
if objfso.folderexists(strlocalpath & objnodelist(i).text)=falsethen
objfso.createfolder(strlocalpath & objnodelist(i).text)
endif
response.write "创建目录"& objnodelist(i).text &"<br/>"
response.flush
next
set objfso =nothing
set objnodelist =nothing
set objnodelist = objxmlfile.documentelement.selectnodes("//file/path")
j = objnodelist.length -1
for i =0to 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 &"<br/>"
response.flush
.close
endwith
set objstream =nothing
next
set objnodelist =nothing
endif
endif
set objxmlfile =nothing
response.write "文件解包完毕"
%>
</body>
</html>