Note:

You can find the CFFiddle demo of this function and other file functions as part of a project that is shared with you.

Click the button below to launch CFFiddle.

To copy the project in your workspace in CFFiddle, follow the steps below:

  1. Log in with your Gmail or Facebook credentials.
  2. Navigate to the project in the left pane.
  3. Once you make some changes in any cfm in the project, a pop up displays asking you to save the project.
  4. Give the project a suitable name and click Save.
  5. Create a folder named dir1 and upload a text file, myfile.txt.

Description

Deletes the specified on-disk or in-memory file on the server.

Category

System functions

Function syntax

FileDelete(filepath)

See also

FileCloseFileIsEOFFileOpenFileReadFileReadLineFileWritecffile

History

ColdFusion 8: Added this function.

Parameters

Parameter

Description

filepath

Pathname of the on-disk or in-memory file to delete. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the getTempDirectory function.

Usage

Use this function to free the memory used by an in-memory file. For more information on using in-memory files, see Working with in-memory files in the Developing ColdFusion Applications.

Example

The following example deletes the file c:\productiondir\test1.txt before moving c:\testdir\test1.txt:

<h3>FileDelete Example</h3>

<cfset sourcefile="c:\testdir\test1.txt">
<cfset destinationfile="c:\productiondir\test1.txt">

<cfif FileExists(#sourcefile#)>
<cfif FileExists(#destinationfile#)>
<cfoutput>The destination file already exists.<br>
Deleting previous copy of #destinationfile#.<br>
Moving: #sourcefile# <br>
To: <br> #destinationfile#.</cfoutput><br>
<cfscript>
FileDelete(#destinationfile#);
FileMove(#sourcefile#, #destinationfile#);
</cfscript>
<cfelse>
<cfscript>
FileMove(#sourcefile#, #destinationfile#);
</cfscript>
<cfoutput>Moved: #sourcefile# <br>
To: <br> #destinationfile#.</cfoutput><br>
</cfif>
<cfelse>
<cfoutput>The source file does not exist.</cfoutput><br>
</cfif>

 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy