CFLib.org – Common Function Library Project

FileCreate(filename[, force])

Last updated February 20, 2003

author

Jesse Houwing

Version: 1 | Requires: CF5 | Library: FileSysLib

Description:
This will create a new file, only if a file with the given name does not exist. Use force=true to overwrite a file that already exists

Return Values:
Returns nothing.

Example:

<!---
<cfset filename="c:\autoexec.bat">
<cfset FileCreate(filename, false)> <!--- probably won't work --->
<cfset FileCreate(filename, true)> <!--- will truncate your autoexec.bat --->
--->

Parameters:

Name Description Required
filename Filename to create. Yes
force Force creation (will nuke existing file). Defaults to false. No

Full UDF Source:

/**
 * Create a new file.
 * 
 * @param filename 	 Filename to create. (Required)
 * @param force 	 Force creation (will nuke existing file). Defaults to false. (Optional)
 * @return Returns nothing. 
 * @author Jesse Houwing (j.houwing@student.utwente.nl) 
 * @version 1, February 20, 2003 
 */
function FileCreate(filename){
	var force = false;
	var daFile = createObject('java', 'java.io.File');
	
	if(arraylen(arguments) gte 2) force = arguments[2];
	daFile.init(JavaCast('string', filename));
	if(force) daFile.delete();
	daFile.createNewFile();
}
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