CFLib.org – Common Function Library Project

setFileDate(filename[, newDate])

Last updated June 14, 2011

author

James Moberg

Version: 1 | Requires: CF9 | Library: FileSysLib

Description:
Updates the dateLastModified file attribute.

Return Values:
Returns a boolean.

Example:

<cfscript>
setFileDate("c:\image.jpg", "1/1/2005 13:00:00");
</cfscript>

Parameters:

Name Description Required
filename Absolute filename. Yes
newDate Date/Time to assign. Defaults to current time. No

Full UDF Source:

/**
 * Updates the dateLastModified file attribute.
 * 
 * @param filename      Absolute filename. (Required)
 * @param newDate      Date/Time to assign. Defaults to current time. (Optional)
 * @return Returns a boolean. 
 * @author James Moberg (james@ssmedia.com) 
 * @version 1, June 14, 2011 
 */
function setFileDate(filename){
    var newDate = Now();
    if (ArrayLen(Arguments) GTE 2) { newDate = arguments[2]; }
    if (not isdate(newDate)) { return false; }
    else if (newDate LT '1/1/1970') { return false; }
    if (not fileExists(filename)) { return false; }
    newDate = DateDiff("s", DateConvert("utc2Local", "January 1 1970 00:00"), newDate) * 1000;
    return CreateObject("java","java.io.File").init(JavaCast("string",filename)).setLastModified(newDate);
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson