Getting a file's timestamp using ColdFusion
Finding a file's date/time is now quite easy in ColdFusion by simply making use of the underlying Java File and Date objects. A bit of code ...
<cfset fileObj = createObject("java","java.io.File").init(expandPath(filePath))>
<cfset fileDate = createObject("java","java.util.Date").init(fileObj.lastModified())>
At this point the fileDate variable contains a normal ColdFusion date.
Couple of notes:
The java.io.File object gets information about the file, but does not read the file into memory. That's good.
The lastModified() method here returns a number (a 'long'), which is exactly what the java.util.Date object needs to create the Date object.
Remember not to use the variable name 'file' in your code. This appears to be a reserved name.
