CFLib.org – Common Function Library Project

FileCreate(filename [, force])

Last updated February 20, 2003
Download UDF

author

Jesse Houwing                                     Jesse Houwing

Version: 1 | Requires: ColdFusion 5 | 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:

<cfscript>
/**
* 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();
}
</cfscript>

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
2 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson