Jul
04
2002
ASP Getting last modified date of a file
Posted by admin under
Filehandling
Function File_GetLastModified(sPath)
If sPath = "" Then
sPath = Server.MapPath(Request.ServerVariables("SCRIPT_NAME"))
End If
Set objFileObj = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFileObj.GetFile(sPath)
File_GetLastModified = objFile.DateLastModified
Set objFile = Nothing
Set objFileObj = Nothing
End Function
<%
Response.Write "c:\test.txt was modified:" & File_GetLastModified("c:\test.txt")
Response.Write "This file is modified:" & File_GetLastModified("")
%>
So this way, by specifying empty string as input you get the date and time when your ASP-file was last modified.
If you don't know the exact path to the file ( like c:\www\hello.txt ) - you might just know the file is located under the /files/ subdirectory at your webhost then you need to convert the path using Server.MapPath. Check out our String functions section for examples.