pf » Finding the Last Modified Date on a File
Finding the Last Modified Date on a File
This question came up on my local CFUG mailing list yesterday:
how can I get the time last updated of the two documents? I know you can do this with uploaded files using FILE.TimeLastModified. Is there anyway to do it with existing files? I know I could do a hack with CFDIRECTORY where I loop through the files in the directory looking for the one I'm interested in and then getting the dateLastModified on that, but I'm thinking there has to be a more direct way.
You can use java's File class to get the lastModified timestamp:
<cfset myFile = CreateObject("java", "java.io.File")>
<cfset myFile.init("/path/to/file")>
<cfset last_modified = myFile.lastModified()>
Related Entries
- Serializing CFC's in ColdFusion 8 - August 6, 2007
- ColdFusion on the TIOBE index - March 18, 2006
- Null Java References in CF 6 vs 7 - January 10, 2006
- DNS Query with ColdFusion - October 27, 2005
- Build a directory browser with ColdFusion - September 12, 2005
There is also the filter attribute to cfdirectory that would negate the need to loop over and look for the file. Still I think the Java File solution is better.
No need to loop. :)
Its slower, but more portable.
I want to display last modified date in HTML page.
Returns: A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
I suppose you'd have to compare it at the ms level in that case -
<cfset y = datediff('s','00:00:00 January 1, 1970',now())*1000/>
<cfset y = datediff('s',LSParseDateTime('January 1, 1970 00:00:00 AM GMT'),now())*1000/>
This will convert the Base Jan 1970 time into MS where you can then use simple math to do your comparisons at the MilliSeconds level.
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
- 10 Most Useful Image Functions in ColdFusion 8
- Speaking at NYC CFUG This Week
- Adobe AIR Tutorial for HTML / JavaScript Developers
- INFORMATION_SCHEMA Support in MySQL, PostgreSQL
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in










