473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

page title in a list of recently updated pages

Hi there,

I'm using VBScript to display a list of the ten most recently updated
pages on my web site. Right now, the script lists the filenames and
the date modified in a given directory.

What I want to know is if there is any way to extract the page title
and display that instead of the file name? Can I use .asp and VBscript
to "delve" into the file and extract the title?

Here's the code I'm using:
<%
folder = ".\"
set fso = CreateObject("Scripting.fileSystemObject")
set fold = fso.getFolder(Server.MapPath(folder))
fileCount = fold.files.count
dim fNames(), fDates()
redim fNames(fileCount), fDates(fileCount)
cFcount = 0
for each file in fold.files
cFcount = cFcount + 1
fNames(cFcount) = lcase(file.name)
fDates(cFcount) = file.dateLastModified
next
for tName = 1 to fileCount
for nName = (tName + 1) to fileCount
if (fDates(tName) < fDates(nName)) then
buffer = fNames(nName)
dateBuffer = fDates(nName)
fNames(nName) = fNames(tName)
fDates(nName) = fDates(tName)
fNames(tName) = buffer
fDates(tName) = dateBuffer
end if
next
next
if (fileCount > 10) then
fileCount = 10
End If
Response.Write "<table border=1 width='90%'>"
for i = 1 to fileCount
Response.Write "<tr><td><a href='" & fNames(i) & "'>" &
fNames(i) & "</a></td><td>" & fDates(i) & "</td></tr>"
next
Response.Write "</table>"
%>

Apr 19 '06 #1
5 2434

no****@plasticlegs.com wrote:
Hi there,

I'm using VBScript to display a list of the ten most recently updated
pages on my web site. Right now, the script lists the filenames and
the date modified in a given directory.

What I want to know is if there is any way to extract the page title
and display that instead of the file name? Can I use .asp and VBscript
to "delve" into the file and extract the title?

Here's the code I'm using:
<%
folder = ".\"
set fso = CreateObject("Scripting.fileSystemObject")
set fold = fso.getFolder(Server.MapPath(folder))
fileCount = fold.files.count
dim fNames(), fDates()
redim fNames(fileCount), fDates(fileCount)
cFcount = 0
for each file in fold.files
cFcount = cFcount + 1
fNames(cFcount) = lcase(file.name)
fDates(cFcount) = file.dateLastModified
next
for tName = 1 to fileCount
for nName = (tName + 1) to fileCount
if (fDates(tName) < fDates(nName)) then
buffer = fNames(nName)
dateBuffer = fDates(nName)
fNames(nName) = fNames(tName)
fDates(nName) = fDates(tName)
fNames(tName) = buffer
fDates(tName) = dateBuffer
end if
next
next
if (fileCount > 10) then
fileCount = 10
End If
Response.Write "<table border=1 width='90%'>"
for i = 1 to fileCount
Response.Write "<tr><td><a href='" & fNames(i) & "'>" &
fNames(i) & "</a></td><td>" & fDates(i) & "</td></tr>"
next
Response.Write "</table>"
%>


Yes. You can use the Scripting.FileSystemObject to read the contents
of an asp file, and then a regular expression to get the title. Here's
one that opens a file in the same folder and finds the title. It
assumes that you will only have letters, numbers or spaces in the
title:

<%
Dim objFSO, objTextStream, strSearchOn, objMatch, colmatches, mymatch
Dim strFileName
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strFileName = Server.Mappath("filename.asp")
const fsoForReading = 1
Set objTextStream = objFSO.OpenTextFile(strFileName, fsoForReading)
strSearchOn = objTextStream.ReadAll
Set objRegExpr = New regexp
objRegExpr.Pattern = "<title>[\w\d\s]*<"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
set colmatches = objRegExpr.Execute(strSearchOn)
For Each objMatch in colMatches
mymatch = replace(objMatch.Value,"<title>","")
mymatch = replace(mymatch,"<","")
Next
Response.Write mymatch
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
%>

--
Mike Brind

Apr 19 '06 #2
Thanks Mike! I was able to insert that script into my code to give me
exactly what I want! One last thing - is there any way to allow dashes
in the title?

Apr 20 '06 #3

no****@plasticlegs.com wrote:
Thanks Mike! I was able to insert that script into my code to give me
exactly what I want! One last thing - is there any way to allow dashes
in the title?


Yes. Add \- to the pattern within the square brackets, so the line
should read:

objRegExpr.Pattern = "<title>[\w\d\s\-]*<"

Hyphens/Dashes need to be escaped with a backslash because it's one of
the special characters. The pattern above first looks for the text
<title>, followed by any word character or digit or whitespace or dash
appearing 0 or more times before an opened angle bracket.

If you find you need to add more options (double colons :: seem to be
the rave with some people), have a look at this article:

http://msdn.microsoft.com/library/de...ting051099.asp

--
Mike Brind

Apr 20 '06 #4
Mike Brind wrote on 20 apr 2006 in microsoft.public.inetserver.asp.general:
Yes. Add \- to the pattern within the square brackets, so the line
should read:

objRegExpr.Pattern = "<title>[\w\d\s\-]*<"


Why not more general:

"<title>[^<]*<"

?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 20 '06 #5
Thanks Mike! I was able to insert that script into my code to give me
exactly what I want! One last thing - is there any way to allow dashes
in the title?

Oops, never mind, I just solved it:

Replace
objRegExpr.Pattern = "<title>[\w\d\s]*<"

With
objRegExpr.Pattern = "<title>[\w\d\s\x2D]*<"

Thanks again!

Apr 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
6
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
5
by: Maxim Izbrodin | last post by:
Hello For displaying page titles for my ASP.NET applications I use the following technique <title><%=BannerModule.PageTitle%></title where BannerModule.PageTitle is a public field of my user...
3
by: Dan Nash | last post by:
Weird problem... all my pages use C# codebehind to set the <title> tag of the pages. As follows... in hmtl.. <title id="PageTitle"></title> in code.. protected...
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
1
by: Dunc | last post by:
Hi, I'm using ASP.NET 2.0's master pages feature (very nice), and I'm setting the page title programatically (Master.Page.Title = "abc";) based on a database read. Whenever a button is pushed...
2
by: jed | last post by:
Hi guys. I have a html page which I want to print. The page simply contains A page/title header, say "Web Printing 101" and some body text. Now I send to a printer and everythings fine. My problem is...
10
by: StarWallace | last post by:
http://microstudios.co.cc/ I assume that this should be quite easy but i just cant figure this out at all... I'm trying to make it so that the title of the page changes depending on the page that...
1
by: DavidFin | last post by:
I am putting together a website using php include and I am finding it difficult to find a way to include the title and meta tags from each include file since the page I am including them on already...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.