Finding the Last Modified Date on a File
By Pete Freitag
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()>
Finding the Last Modified Date on a File was first published on January 11, 2007.
If you like reading about java, coldfusion, file, or cfdirectory then you might also like:
- Spring4Shell and ColdFusion
- Log4j CVE-2021-44228 Log4Shell Vulnerability on ColdFusion / Lucee
- URL Safe Base64 Encoding / Decoding in CFML
- Updating Java on ColdFusion or Lucee
The FuseGuard Web Application Firewall for ColdFusion & CFML is a high performance, customizable engine that blocks various attacks against your ColdFusion applications.