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);
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson