Whilst looking at creating dynamic Sitemaps for Google bot spidering I found that I needed to populate an XML node with the last modified date of the templates. I figured there must be a programmatic way of doing this, so after some searching around this is what I ended out with:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(getcurrenttemplatepath()).lastModified())>
1<cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(getcurrenttemplatepath()).lastModified())>
This creates a java object, using the date and file utilities we can use 'getcurrenttemplatepath()' to provide the path data, finally referencing the lastModified property.
A handy and relatively quick way of getting the last modified date.
It is a bit of a mouthful though, so might be easier to create it as a handy referencable object:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cffunction name="modStamp" access="public" returntype="date" output="no" hint="Gets the last mod date of a file, returns a ts">
<cfargument name="file" type="string" required="yes" hint="File to get mod date">
<cfset var mod_time = now()>
<cfif fileexists(arguments.file)>
<cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(arguments.file).lastModified())>
</cfif>
<cfreturn mod_time>
</cffunction>
1<cffunction name="modStamp" access="public" returntype="date" output="no" hint="Gets the last mod date of a file, returns a ts">
2 <cfargument name="file" type="string" required="yes" hint="File to get mod date">
3 <cfset var mod_time = now()>
4
5 <cfif fileexists(arguments.file)>
6 <cfset mod_time = createObject("java", "java.util.Date").init(createObject("java", "java.io.File").init(arguments.file).lastModified())>
7 </cfif>
8
9 <cfreturn mod_time>
10</cffunction>
Then you can just do:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cfset variables.fileMod = modStamp()>
1<cfset variables.fileMod = modStamp()>
There are no comments for this entry.
[Add Comment] [Subscribe to Comments]