Used to generate sitemap.xml files of things, for Google and other search engines to crawl.
Copy Code code as follows:
<%
server.scripttimeout=50000
' Sitemap_gen.asp
' A simple script to automatically produce sitemaps for A webserver, in the Google Sitemap Protocol (GSP)
' By Francesco Passantino
' Www.iteam5.net/francesco/sitemap
' v0.2 released 5 June (Listing a directory tree recursively improvement)
'
' BSD 2.0 License,
' Http://www.opensource.org/licenses/bsd-license.php
' Collection and collation: Chongqing Forest @im286.com
Session ("server") = "Http://www.jb51.net"
' Your domain
VDir = "/"
' Directory to make sitemap, relative directory (relative to root directory)
Set objFSO = CreateObject ("Scripting.FileSystemObject")
Root = Server.MapPath (VDir)
' Response. ContentType = "Text/xml"
' Response.Write ' <?xml version= ' 1.0 ' encoding= ' UTF-8 '?> '
' Response.Write ' <urlset xmlns= ' http://www.google.com/schemas/sitemap/0.84 ' > '
str = "<?xml version= ' 1.0 ' encoding= ' UTF-8 '?> '" & vbCrLf
str = str & "<urlset xmlns= ' http://www.google.com/schemas/sitemap/0.84 ' >" & vbCrLf
Set objfolder = Objfso.getfolder (Root)
' Response.Write Getfilelink (objfolder.path,objfolder.datelastmodified)
Set colfiles = Objfolder.files
For each objfile in Colfiles
' Response.Write Getfilelink (objfile.path,objfile.datelastmodified)
str = str & Getfilelink (objfile.path,objfile.datelastmodified) & vbCrLf
Next
ShowSubFolders (objfolder)
' Response.Write ' </urlset> '
str = str & "</urlset>" & vbCrLf
Set fso = Nothing
Set objstream = Server.CreateObject ("ADODB. Stream ")
With Objstream
'. Type = adTypeText
'. Mode = adModeReadWrite
. Open
. Charset = "Utf-8"
. Position = Objstream.size
. Writetext=str
. SaveToFile Server.MapPath ("/sitemap.xml"), 2 ' generated XML filename
. Close
End With
Set objstream = Nothing
If not ERR Then
Response.Write ("<script>alert" (' success! '); History.back ();</script> ")
Response.End
End If
Sub ShowSubFolders (objfolder)
Set colfolders = objfolder.subfolders
For each objsubfolder in Colfolders
If Folderpermission (Objsubfolder.path) Then
' Response.Write Getfilelink (objsubfolder.path,objsubfolder.datelastmodified)
str = str & Getfilelink (objsubfolder.path,objsubfolder.datelastmodified) & vbCrLf
Set colfiles = Objsubfolder.files
For each objfile in Colfiles
' Response.Write Getfilelink (objfile.path,objfile.datelastmodified)
str = str & Getfilelink (objfile.path,objfile.datelastmodified) & vbCrLf
Next
ShowSubFolders (Objsubfolder)
End If
Next
End Sub
Function Getfilelink (File,datafile)
File=replace (file, "\", "/")
File=replace (File,root, "")
If Fileextensionisbad (file) then Exit Function
If month (datafile) <10 then filedatem= "0"
If Day (datafile) <10 then filedated= "0"
Filedate=year (datafile) & "-" &filedatem&month (datafile) & "-" &filedated&day (datafile)
Getfilelink = "<url><loc>" &server.htmlencode (Session ("Server") &file) & "</loc>< Lastmod> "&filedate&" </lastmod><changefreq>daily</changefreq><priority>1.0 </priority></url> "
Response.Flush
End Function
Function folderpermission (PathName)
' Directory (not listed in Sitemap) that needs to be filtered
Pathexclusion=array ("\da@ta78#9", "\member", "\admin", "\dxyeditor")
Folderpermission =true
For each pathexcluded in Pathexclusion
If InStr (UCase (PathName), UCase (pathexcluded)) >0 Then
Folderpermission = False
Exit For
End If
Next
End Function
Function Fileextensionisbad (sFileName)
Dim sfileextension, Bfileextensionisvalid, Sfileext
' Modify for your file extension (http://www.googleguide.com/file_type.html)
Extensions = Array ("PNG", "gif", "JPG", "jpeg", "Zip", "PDF", "PS", "html", "htm", "php", "WK1", "Wk2", "WK3", "Wk4", "Wk5", " Wki "," wks "," WKU "," LWP "," MW "," xls "," ppt "," Doc "," SwF "," wks "," WPS "," wdb "," WRI "," RTF "," ans "," txt ")
' Set the file name of the list, and the extension is not included in the Sitemap will not include the file for that extension
If Len (Trim (sfilename)) = 0 Then
Fileextensionisbad = True
Exit Function
End If
Sfileextension = Right (sFileName, Len (sfilename)-InStrRev (sFileName, "."))
Bfileextensionisvalid = False ' assume extension is bad
For each sfileext in extensions
If UCase (sfileext) = UCase (sfileextension) Then
Bfileextensionisvalid = True
Exit For
End If
Next
Fileextensionisbad = Not Bfileextensionisvalid
End Function
%>