CFLib.org – Common Function Library Project

FileCreate(filename [, force])

Last updated February 20, 2003

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

 
Rated 0 time(s). Average Rating: 0

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:

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

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

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

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson