Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
IMCreator - Free Website Builder

ColdFusion Delete File

You can use the cffile tag to delete a file from the server.

Example of Deleting a File

The following code deletes the file specified with the file attribute.

<cffile action="delete"
	file="C:\docs\accessLog.txt">

Checking that the File Exists

The above code will work properly if the file actually exists. If the file doesn't exist, the user will receive an error.

You can use the built in ColdFusion FileExists() function to check if the file exists. By using this as an expression in a cfif statement, you can determine what to do if the file doesn't exist.

<cfif FileExists("C:\docs\accessLog.txt")>
   <cffile action="delete"
	   file="C:\docs\accessLog.txt">
<cfelse>
   <p>Sorry, can't delete the file - it doesn't exist.</p>
</cfif>

If the file doesn't exist, the following message will be displayed to the user:

Sorry, can't delete the file - it doesn't exist.

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!