CFLib.org – Common Function Library Project

setFileDate(filename [, newDate])

Last updated June 14, 2011

Version: 1 | Requires: ColdFusion 9 | Library: FileSysLib

 
Rated 0 time(s). Average Rating: 0

Description:
Updates the dateLastModified file attribute.

Return Values:
Returns a boolean.

Example:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Robby Lansaw Robby Lansaw added
getComponentProp...
3 day(s) ago

Dave Anderson Dave Anderson added
iniToStruct
25 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
25 day(s) ago

Richard Richard added
dice
27 day(s) ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson