Created
September 28, 2023 13:55
-
-
Save evagoras/337ce1029ca8aaaf8711a40ce672f63a to your computer and use it in GitHub Desktop.
Generating an XML file of your website’s folders/files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@Language="VBScript"%> | |
<%Option Explicit%> | |
<%Response.Buffer = True%> | |
<% | |
'-- set a 600 second timeout value in case it hangs | |
Server.ScriptTimeOut = 600 | |
On Error Resume Next | |
Dim strRootFolder | |
Dim intLenRootFolder | |
Dim objFSO | |
Dim strXmlFile | |
Dim strVbCrLf | |
Dim strVbTab | |
Dim numTree | |
Dim objFile | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
'-- if there are files in the folder | |
If Not IsEmpty(objSubFile) Then | |
For Each objthisFile in objSubFile | |
'-- properly nest the nodes for a nice display | |
For i = 0 To thisTree + 1 | |
strXmlFile = strXmlFile & strVbTab | |
Next | |
'-- get the virtual path | |
strURL = Mid(objthisFile.Path, intLenRootFolder, Len(objthisFile.Path)) | |
strURL = Replace(strURL, "\", "/") | |
'-- create output string | |
strXmlFile = strXmlFile & "<document type=""document"" value=""" & objthisFile.Name | |
& """ url=""" & strURL & """/>" & strVbCrLf | |
Next | |
'-- write output to XML file | |
objFile.Write(strXmlFile) | |
strXmlFile = "" | |
End If | |
For i = 1 To thisTree | |
strXmlFile = strXmlFile & strVbTab | |
Next | |
'-- close the folder node | |
If thisTree > 0 Then | |
strXmlFile = strXmlFile & "</folder>" & strVbCrLf | |
End If | |
objFile.Write(strXmlFile) | |
strXmlFile = "" | |
'-- show the progress of the code as it goes through folders | |
Response.Write("Folder <font color=""#FF0000"">" & strFolderURL & "</font> written!<br>") | |
Response.Flush | |
End Sub | |
'--write end root node | |
objFile.Write("</root>") | |
objFile.close | |
Set objFile = Nothing | |
Set objFSO = Nothing | |
%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
strXmlFile = strXmlFile & "<document type=""document"" value=""" & objthisFile.Name | |
& """ url=""" & strURL & """" & " datelastmodified=""" & objthisFile.DateLastModified & """/>" & strVbCrLf | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
strVbCrLf = VbCrLf | |
strVbTab = VbTab | |
numTree = 0 | |
strRootFolder = Request.ServerVariables("APPL_PHYSICAL_PATH") | |
intLenRootFolder = Len(strRootFolder) | |
strXmlFile = "<root type=""root"" value=""Site Root"" url=""/"">" & strVbCrLf | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
'-- reset the string which gets written to the XML file | |
strXmlFile = "" | |
'-- declare our variables in the sub | |
Dim objFolder, objSubFolder, objSubFile, i | |
Dim objThisFolder, objthisFile, strURL, strFolderURL | |
'-- grab the folder passed in the sub | |
Set objFolder = objFSO.GetFolder(strFolder) | |
'-- grab its subfolders | |
Set objSubFolder = objFolder.SubFolders | |
'-- grab its files | |
Set objSubFile = objFolder.Files | |
'-- properly nest the nodes for a nice display | |
For i = 1 To thisTree | |
strXmlFile = strXmlFile & strVbTab | |
Next | |
'-- get the folder path excluding the application root folder | |
strFolderURL = Mid(objFolder.Path, intLenRootFolder, Len(objFolder.Path)) | |
'-- turn the physical path into a relative path | |
strFolderURL = Replace(strFolderURL, "\", "/") | |
'-- append node to the output unless it is the root folder | |
If thisTree > 0 Then | |
strXmlFile = strXmlFile & "<folder type=""folder"" value=""" & objFolder.Name & """ | |
url=""" & strFolderURL & "/"">" & strVbCrLf | |
objFile.Write(strXmlFile) | |
End If | |
'-- reset the string output again | |
strXmlFile = "" | |
'-- if there are subfolders under it then run sub again for each one | |
If Not IsEmpty(objSubFolder) Then | |
For Each objThisFolder in objSubFolder | |
Call TraverseSite(objThisFolder.Path,thisTree + 1) | |
Next | |
End If | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
Call TraverseSite(strRootFolder,numTree) | |
Sub TraverseSite(strFolder,thisTree) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
'-- create an instance of the FSO object | |
Set objFSO = Server.CreateObject("Scripting.FileSystemObject") | |
'-- open file for writing, create if not there, and open as text | |
Set objFile = objFSO.CreateTextFile(strRootFolder & "menuitems.xml", True, False) | |
'-- write root node | |
objFile.Write(strXmlFile) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://evagoras.com/2011/02/08/generating-an-xml-file-of-your-websites-foldersfiles/