Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Advanced
Feb 25, 2000

Determine Last Modified Date With the FileSystemObject

I often go to a site, scroll to the bottom, and see when it was last modified. If it says "March 1, 1825" then I am usually not so confident that the content is timely. Unfortunately, sometimes it is just the poor overworked Webmaster who has not had time to update the date on the page. Why do it manually when Microsoft provides the FileSystemObject, which can retrieve all kinds of information about files, including when it was last modified? Place this script at the bottom of your page and you'll see what I am talking about:

 
<%
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
dir = Server.MapPath(".")

'Get the files collection
Set colFiles = objFileSystem.GetFolder(dir).Files
	
defaultDate = #3/1/1825#
latestDate = defaultDate

For Each file in colFiles
	filedate = file.DateLastModified
	if DateDiff("s", defaultDate, filedate) > 0 Then
		latestDate = fileDate
	End If
Next
Response.Write(latestDate)
%>

Basically, you can retrieve the collection of files in the same directory with the FileSystemObject. Once you have that, you can determine the latest modified date by comparing the DateLastModified property versus an arbitrary date (defaultDate) for each one. Output it to the browser and you are all set.

Bill Pitzer
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date