473,585 Members | 2,536 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("S cripting.fileSy stemObject")
set fold = fso.getFolder(S erver.MapPath(f older))
fileCount = fold.files.coun t
dim fNames(), fDates()
redim fNames(fileCoun t), fDates(fileCoun t)
cFcount = 0
for each file in fold.files
cFcount = cFcount + 1
fNames(cFcount) = lcase(file.name )
fDates(cFcount) = file.dateLastMo dified
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 2449

no****@plasticl egs.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("S cripting.fileSy stemObject")
set fold = fso.getFolder(S erver.MapPath(f older))
fileCount = fold.files.coun t
dim fNames(), fDates()
redim fNames(fileCoun t), fDates(fileCoun t)
cFcount = 0
for each file in fold.files
cFcount = cFcount + 1
fNames(cFcount) = lcase(file.name )
fDates(cFcount) = file.dateLastMo dified
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.FileS ystemObject 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.CreateOb ject("Scripting .FileSystemObje ct")
strFileName = Server.Mappath( "filename.a sp")
const fsoForReading = 1
Set objTextStream = objFSO.OpenText File(strFileNam e, fsoForReading)
strSearchOn = objTextStream.R eadAll
Set objRegExpr = New regexp
objRegExpr.Patt ern = "<title>[\w\d\s]*<"
objRegExpr.Glob al = True
objRegExpr.Igno reCase = True
set colmatches = objRegExpr.Exec ute(strSearchOn )
For Each objMatch in colMatches
mymatch = replace(objMatc h.Value,"<title >","")
mymatch = replace(mymatch ,"<","")
Next
Response.Write mymatch
objTextStream.C lose
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****@plasticl egs.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.Patt ern = "<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.publi c.inetserver.as p.general:
Yes. Add \- to the pattern within the square brackets, so the line
should read:

objRegExpr.Patt ern = "<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.Patt ern = "<title>[\w\d\s]*<"

With
objRegExpr.Patt ern = "<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
38326
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 pages using the require_once function. That is, each page includes the line <?require_once('PageStart.php')?>
6
2466
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
5
2906
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 control. This field is initialized in Page_Load of every my page. This technique works with the exception that the title disappears every time a page is...
3
1124
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 System.Web.UI.HtmlControls.HtmlGenericControls PageTitle;
14
3472
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>..... I want to completely seperate the code from presentation. I would like to do the same thing for a value of a hidden form field but
1
1213
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 on the page, the page reloads, the !Page.IsPostback is skipped, but the title on the master page is reset to the default.
2
1526
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 when the body text span to more than a page (e.g page2,page3). I still want to print (retain) the page title on these succeding pages, just like in...
10
3179
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 is included into my base index.php. i have things set up within the index.php so that i use this code <?php if (!isset($_GET)) {...
1
1607
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 has, and needs, a header tag for java pop up menu. I found what seems to be a solution but it only works for one include page. <html> <head> <?php...
0
7904
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7835
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5386
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2340
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.