当前位置:K88软件开发文章中心编程语言XmlXml01 → 文章内容

将asp程序制作成为安装版:xml打包和解包

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 9:25:47

首先是打包(谈不上压缩,不过经常用ftp的情况下,经常这样打包会好很多的,ftp最怕的就是零碎文件太多,况且现在的网络情况...)

 

打包代码
 

  1. <
    %@LANGUAGE=
    "VBSCRIPT" 
    CODEPAGE=
    "65001"%>
     
  2. <

    Option 
    Explicit 
    %>
     
  3. <

    On 
    Error 
    Resume 
    Next 
    %>
     
  4. <

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

    Server.ScriptTimeout=99999999 
    %>
     
  6. <
    !DOCTYPE 
    html 
    PUBLIC 
    "-//W3C//DTD 
    XHTML 
    1.0 
    Transitional//EN"
     
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
     
  7. <
    html 
    xmlns=
    "http://www.w3.org/1999/xhtml">
     
     
  8. <
    head>
     
     
  9. <
    meta 
    http-equiv=
    "Content-Type" 
    content=
    "text/html
     
    charset=utf-8"
     
    />
     
     
  10. <
    title>
    文件打包程序<
    /title>
     
     
  11. <
    /head>
     
     
  12. <
    body>
     
     
  13. <

  14. Dim 
    ZipPathDir, 
    ZipPathFile, 
    ZipFileExt 
  15. Dim 
    startime, 
    endtime 
  16. '此为默认当前文件夹 
  17.  
  18. ZipPathDir 

    Left(Request.ServerVariables("PATH_TRANSLATED"), 
    InStrRev(Request.ServerVariables("PATH_TRANSLATED"), 
    "\")) 
  19. '在此更改要打包文件夹的路径 
  20.  
  21. 'ZipPathDir="D:\MYWEB\WEBINFO" 
  22.  
  23. '生成的xml文件 
  24.  
  25. ZipPathFile 

    "update.xml" 
  26. '不进行打包的文件扩展名 
  27.  
  28. ZipFileExt 

    "db
    bak"
     
  29. If 
    Right(ZipPathDir, 
    1)<
    >
    "\" 
    Then 
    ZipPathDir 

    ZipPathDir&
    "
    \" 
  30. '开始打包 
  31.  
  32. CreateXml(ZipPathFile) 
  33. '遍历目录内的所有文件以及文件夹 
  34.  
  35. Sub 
    LoadData(DirPath) 
  36.  
     
     
     
    Dim 
    XmlDoc 
  37.  
     
     
     
    Dim 
    fso 
    'fso对象 
  38.  
  39.  
     
     
     
    Dim 
    objFolder 
    '文件夹对象 
  40.  
  41.  
     
     
     
    Dim 
    objSubFolders 
    '子文件夹集合 
  42.  
  43.  
     
     
     
    Dim 
    objSubFolder 
    '子文件夹对象 
  44.  
  45.  
     
     
     
    Dim 
    objFiles 
    '文件集合 
  46.  
  47.  
     
     
     
    Dim 
    objFile 
    '文件对象 
  48.  
  49.  
     
     
     
    Dim 
    objStream 
  50.  
     
     
     
    Dim 
    pathname, 
    TextStream
    pp, 
    Xfolder, 
    Xfpath, 
    Xfile, 
    Xpath, 
    Xstream 
  51.  
     
     
     
    Dim 
    PathNameStr 
  52.  
     
     
     
    response.Write(
    "=========="&
    DirPath&
    "==========<
    br>
    "

  53.  
     
     
     
    Set 
    fso 

    server.
    CreateObject("scripting.filesystemobject"
  54.  
     
     
     
    Set 
    objFolder 

    fso.GetFolder(DirPath)
    '创建文件夹对象 
  55.  
  56.  
     
     
     
    Response.Write 
    DirPath 
  57.  
     
     
     
    Response.flush 
  58.  
     
     
     
    Set 
    XmlDoc 

    Server.
    CreateObject("Microsoft.XMLDOM"
  59.  
     
     
     
    XmlDoc.load(Server.MapPath(ZipPathFile)) 
  60.  
     
     
     
    XmlDoc.async 

    false 
  61.  
     
     
     
    '写入每个文件夹路径 
  62.  
  63.  
     
     
     
    Set 
    Xfolder 

    XmlDoc.SelectSingleNode(
    "//root").AppendChild(XmlDoc.CreateElement("folder")) 
  64.  
     
     
     
    Set 
    Xfpath 

    Xfolder.AppendChild(XmlDoc.CreateElement(
    "path")) 
  65.  
     
     
     
    Xfpath.text 

    Replace(DirPath, 
    ZipPathDir, 
    ""
  66.  
     
     
     
    Set 
    objFiles 

    objFolder.Files 
  67.  
     
     
     
    For 
    Each 
    objFile 
    in 
    objFiles 
  68.  
     
     
     
     
     
     
     
    If 
    LCase(DirPath 
    &
     
    objFile.Name) 
    <
    >
     
    LCase(Request.ServerVariables("PATH_TRANSLATED")) 
    And 
    LCase(DirPath 
    &
     
    objFile.Name) 
    <
    >
     
    LCase(DirPath 
    &
     
    ZipPathFile) 
    Then 
  69.  
     
     
     
     
     
     
     
     
     
     
     
    If 
    ext(objFile.Name) 
    Then 
  70.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Response.Write 
    "---<
    br/>
    "
     
  71.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    PathNameStr 

    DirPath 
    &
     
    "" 
    &
     
    objFile.Name 
  72.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Response.Write 
    PathNameStr 
    &
     
    "" 
  73.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Response.flush 
  74.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    '================================================ 
  75.  
  76.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    '写入文件的路径及文件内容 
  77.  
  78.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xfile 

    XmlDoc.SelectSingleNode(
    "//root").AppendChild(XmlDoc.CreateElement("file")) 
  79.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xpath 

    Xfile.AppendChild(XmlDoc.CreateElement(
    "path")) 
  80.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Xpath.text 

    Replace(PathNameStr, 
    ZipPathDir, 
    ""
  81.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    '创建文件流读入文件内容,并写入XML文件中 
  82.  
  83.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    objStream 

    Server.
    CreateObject("ADODB.Stream"
  84.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    objStream.Type 


  85.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    objStream.Open() 
  86.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    objStream.LoadFromFile(PathNameStr) 
  87.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    objStream.position 


  88.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xstream 

    Xfile.AppendChild(XmlDoc.CreateElement(
    "stream")) 
  89.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Xstream.SetAttribute 
    "xmlns:dt"
    "urn:schemas-microsoft-com:datatypes" 
  90.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    '文件内容采用二制方式存放 
  91.  
  92.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Xstream.dataType 

    "bin.base64" 
  93.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Xstream.nodeTypedValue 

    objStream.Read() 
  94.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    objStream 

    Nothing 
  95.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xpath 

    Nothing 
  96.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xstream 

    Nothing 
  97.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Set 
    Xfile 

    Nothing 
  98.  
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    '================================================ 
  99.  
  100.  
     
     
     
     
     
     
     
     
     
     
     
    End 
    If 
  101.  
     
     
     
     
     
     
     
    End 
    If 
  102.  
     
     
     
    Next 
  103.  
     
     
     
    Response.Write 
    "<
    p>
    "
     
  104.  
     
     
     
    XmlDoc.Save(Server.Mappath(ZipPathFile)) 
  105.  
     
     
     
    Set 
    Xfpath 

    Nothing 
  106.  
     
     
     
    Set 
    Xfolder 

    Nothing 
  107.  
     
     
     
    Set 
    XmlDoc 

    Nothing 
  108.  
     
     
     
    '创建的子文件夹对象 
  109.  
  110.  
     
     
     
    Set 
    objSubFolders 

    objFolder.SubFolders 
  111.  
     
     
     
    '调用递归遍历子文件夹 
  112.  
  113.  
     
     
     
    For 
    Each 
    objSubFolder 
    in 
    objSubFolders 
  114.  
     
     
     
     
     
     
     
    pathname 

    DirPath 
    &
     
    objSubFolder.Name 
    &
     
    "\" 
  115.  
     
     
     
     
     
     
     
    LoadData(pathname) 
  116.  
     
     
     
    Next 
  117.  
     
     
     
    Set 
    objFolder 

    Nothing 
  118.  
     
     
     
    Set 
    objSubFolders 

    Nothing 
  119.  
     
     
     
    Set 
    fso 

    Nothing 
  120. End 
    Sub 
  121. '创建一个空的XML文件,为写入文件作准备 
  122.  
  123. Sub 
    CreateXml(FilePath) 
  124.  
     
     
     
    '程序开始执行时间 
  125.  
  126.  
     
     
     
    startime 

    Timer() 
  127.  
     
     
     
    Dim 
    XmlDoc, 
    Root 
  128.  
     
     
     
    Set 
    XmlDoc 

    Server.
    CreateObject("Microsoft.XMLDOM"
  129.  
     
     
     
    XmlDoc.async 

    False 
  130.  
     
     
     
    Set 
    Root 

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

  131.  
     
     
     
    XmlDoc.appendChild(Root) 
  132.  
     
     
     
    XmlDoc.appendChild(XmlDoc.CreateElement(
    "root")) 
  133.  
     
     
     
    XmlDoc.Save(Server.MapPath(FilePath)) 
  134.  
     
     
     
    Set 
    Root 

    Nothing 
  135.  
     
     
     
    Set 
    XmlDoc 

    Nothing 
  136.  
     
     
     
    LoadData(ZipPathDir) 
  137.  
     
     
     
    '程序结束时间 
  138.  
  139.  
     
     
     
    endtime 

    Timer() 
  140.  
     
     
     
    response.Write(
    "页面执行时间:" 
    &
     
    FormatNumber((endtime 

    startime), 
    3) 
    &
     
    "秒"
  141. End 
    Sub 
  142. '判断文件类型是否合法 
  143.  
  144. Function 
    ext(filename) 
  145.  
     
     
     
    ext 

    true 
  146.  
     
     
     
    Dim 
    temp_ext, 

  147.  
     
     
     
    temp_ext 

    Split(ZipFileExt, 
    "
    "

  148.  
     
     
     
    For 



    To 
    UBound(temp_ext) 
  149.  
     
     
     
     
     
     
     
    If 
    Mid(filename, 
    InstrRev(filename, 
    "."

    1) 

    temp_ext(e) 
    Then 
    ext 

    false 
  150.  
     
     
     
    Next 
  151. End 
    Function 
  152. %>
     
  153. <
    /body>
     
     
  154. <
    /html>
     


[1] [2]  下一页


将asp程序制作成为安装版:xml打包和解包