Not yet rated

Problem

Find the last modified date of a file.

Solution

One technique is to perform a directory listing filtered to just the file you are interested in, then extract the last modified information. Another technique is to use underlying Java File object which also provides a last modified value.

Detailed explanation

 There are a couple of techniques for finding the last modified date of a file within ColdFusion. 

The first technique performs a directory listing filtered to just the file you are interested in:

<cfset fileDir = "/full/path/to/dir/containing/file/")>

<cfset fileName = "yourfile.txt">

<cfdirectory action="list" directory="#fileDir#"
filter="#fileName#" name="fileInfo">

<cfset fileDate = parseDateTime(fileInfo.dateLastModified)>

 The second technique makes use of ColdFusion's underlying Java:

<cfset filePath = "/full/path/to/yourfile.txt">

<cfset fileObj =
createObject("java","java.io.File").init(filePath)>

<cfset fileDate =
createObject("java","java.util.Date").init(fileObj.lastModified())>
 

 

 


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes