View Full Version : insert a file timestamp

04-12-2006, 06:07 AM
I would like to use ASP to put a 'last revised' date on the bottom of each of my web pages. This can be done using a webbot in Frontpage - is there a simple ASP method to do the same thing?

04-12-2006, 02:51 PM
I can't think of an easy way in ASP.

You can use the FSO

But it means that for every ASP file you load you will have to run this code to grab the name of the file and then use FSO to grab it and then output the variable.

04-13-2006, 02:37 AM
Thanks degsy, that almost gets me there. I don't mind running the script on each page, but I would like a way to automatically feed the name of the currently loaded file to the GetFile method, so I don't have to have a separate script for each page that loads. Is there a way to do this? I'm using this script from the ASP tutorial site you linked me to:

Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile("c:\test.txt")
Response.Write("File created: " & f.DateCreated)
set f=nothing
set fs=nothing
So on that third line, I want to substitute a function that returns the current page's file name rather than manually entering it

04-13-2006, 05:22 AM
I don't want to butt in here however if I understand you right I think this might help you out. Just put the call into your code just before the getfile call
currPage = WhatPage()
and then substitute currPage in where you now have c:\test.txt

Function WhatPage()
WhatPage = Request.ServerVariables("URL")

x = InStrRev(WhatPage,"/",-1)

If x > 0 Then
WhatPage = Mid(WhatPage,x+1)
End If
End Function

If this isn't what you want then sorry for taking up your time.


04-13-2006, 05:33 AM
Yep Baldeagle, that's just what I was after. Thanks so much for your help. Knew it had to be simple...

04-13-2006, 06:14 AM
Well actually, Baldeagle, your function didn't quite work because the server needed the physical path of the file. But this seems to work:

Dim fs,f
Set fs=Server.CreateObject("Scripting.FileSystemObject")
currFile=Request.ServerVariables("APPL_PHYSICAL_PATH") & Mid(Replace(Request.ServerVariables("PATH_INFO"),"/","\"),2)
Set f=fs.GetFile(currFile)
Response.Write("Last revised: " & f.DateLastModified)
set f=nothing
set fs=nothing

Haven't tried it on the live server yet, but fingers crossed!

04-13-2006, 09:13 AM
you could also use ServerVariables("SCRIPT_NAME") to get the filename instead of parsing the url....

04-13-2006, 07:56 PM
My bad on the function. It worked locally for me but I was not caring about the full path.


{edit} Roelf makes a good point. I didn't use it because I have never used it before and was unsure from the description exactly what would be returned. As he said you can eliminate the parsing junk.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum