Determine Last Modified Date With the FileSystemObject

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 collectionSet colFiles = objFileSystem.GetFolder(dir).Files	defaultDate = #3/1/1825#latestDate = defaultDateFor Each file in colFiles	filedate = file.DateLastModified	if DateDiff("s", defaultDate, filedate) > 0 Then		latestDate = fileDate	End IfNextResponse.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.

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist