SoFunction
Updated on 2025-04-08

Tools for packaging asp source code into xml


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> 
<%OptionExplicit%> 
<%OnErrorResumeNext%> 
<% ="UTF-8"%> 
<% =99999999%> 
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http:///TR/xhtml1/DTD/"> 
<htmlxmlns="http:///1999/xhtml"> 
<head> 
<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/> 
<title>File Packaging Program</title>
</head> 

<body> 
<% 


Dim ZipPathDir, ZipPathFile 
Dim startime, endtime 
'Change the path to the folder to be packaged here
ZipPathDir ="F:\"' 
ZipPathFile ="" 
If Right(ZipPathDir,1)<>"\"Then ZipPathDir = ZipPathDir&"\" 
'Start packing
CreateXml(ZipPathFile) 
'Travel through all files and folders in the directory

Sub LoadData(DirPath) 
Dim XmlDoc 
Dim fso 'fso object
Dim objFolder 'Folder Object
Dim objSubFolders' subfolder collection
Dim objSubFolder 'Subfolder object
Dim objFiles' File Collection
Dim objFile 'File Object
Dim objStream 
    Dim pathname, TextStream, pp, Xfolder, Xfpath, Xfile, Xpath, Xstream 
    Dim PathNameStr 
    ("=========="&DirPath&"==========<br>") 
Set fso = ("") 
Set objFolder = (DirPath)'Create a folder object

     DirPath 
     

    Set XmlDoc = ("") 
     (ZipPathFile) 
     =False 

'Write to each folder path
Set Xfolder = ("//root").AppendChild(("folder")) 
Set Xfpath = (("path")) 
     = Replace(DirPath, ZipPathDir,"") 
Set objFiles =  
    ForEach objFile in objFiles 
        If LCase(DirPath & )<> LCase(("PATH_TRANSLATED"))Then 
             "---<br/>" 
            PathNameStr = DirPath &""&  
             PathNameStr &"" 
             
            '================================================ 
'The path to the file and the file content
Set Xfile = ("//root").AppendChild(("file")) 
Set Xpath = (("path")) 
             = Replace(PathNameStr, ZipPathDir,"") 
'Create a file stream to read the file content and write it to the XML file.
Set objStream = ("") 
            =1 
            () 
            (PathNameStr) 
             =0 

Set Xstream = (("stream")) 
             "xmlns:dt","urn:schemas-microsoft-com:datatypes" 
'The file content is stored in a two-system manner
             ="bin.base64" 
             = () 

Set objStream =Nothing 
Set Xpath =Nothing 
Set Xstream =Nothing 
Set Xfile =Nothing 
'================================================ 
EndIf 
Next 
     "<p>" 
    ((ZipPathFile)) 
Set Xfpath =Nothing 
Set Xfolder =Nothing 
Set XmlDoc =Nothing 

'Created subfolder object
Set objSubFolders =  
'Call recursively traverse subfolders
ForEach objSubFolder in objSubFolders 
        pathname = DirPath &  &"\" 
        LoadData(pathname) 
Next 
Set objFolder =Nothing 
Set objSubFolders =Nothing 
Set fso =Nothing 

EndSub 



'Create an empty XML file to prepare for writing to the file

Sub CreateXml(FilePath) 
'Program start execution time
    startime = Timer() 
Dim XmlDoc, Root 
    Set XmlDoc = ("") 
     =False 
Set Root = ("xml","version='1.0' encoding='UTF-8'") 
    (Root) 
    (("root")) 
    ((FilePath)) 
Set Root =Nothing 
Set XmlDoc =Nothing 
    LoadData(ZipPathDir) 
'Program end time
    endtime = Timer() 
("Page execution time: "& FormatNumber((endtime - startime),3)&"seconds")
EndSub 


%> 
</body> 
</html>