View comments | RSS feed
Contents > CFML Reference > ColdFusion Tags > cffile action = "delete" PreviousNext

cffile action = "delete"

Deletes a file on the server.

<cffile 
action = "delete"
file = "full_path_name">

cfdirectory

Attribute

Req/Opt

Default

Description

action

Required

 

Type of file manipulation that the tag performs.

file

Required

 

Pathname of the file to delete.

If not an absolute path (starting a 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.

The following example deletes the specified file:

<cffile action = "delete"
   file = "c:\files\upload\#Variables.DeleteFileName#">

Contents > CFML Reference > ColdFusion Tags > cffile action = "delete" PreviousNext

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6.1

Comments are no longer accepted for ColdFusion MX 6.1. ColdFusion 8 is the current version.

Comments


No screen name said on Sep 2, 2003 at 3:55 AM :
Hi,

I am using coldfusion 6, (red sky) on Linux. There seems to be a bug with the delete fuction.

I am trying the following:

<cffile action="delete" file="/data/home.htm">

and the error returned is:

ColdFusion could not delete the file "/data/home.htm" for an unknown reason.

I have tried playing with permissions etc, but to no avail.

Can you help me?

Thanks,

David
M_Howard said on Sep 15, 2003 at 12:23 PM :
You either need to use an absolute path (e.g., "c:\inetpub\yoursite\yourdirectory\yourfile.doc") or you need to return the GetTempDirectory like this: file="#GetTempDirectory()#\data\home.htm"

Your safest bet is to get the absolute path to the folder on your server where the site is kept. You can get this from your administrator or from your hosting company.
TheoPeters said on Sep 25, 2003 at 11:42 AM :
M_howard, /data/home.htm IS an absolute path.
No screen name, try checking the permissions on the file. See if the user Coldfusion is running as has permissions to delete the file.

(use ps -ef | grep coldfusion to find who coldfusion is running as)
(use ls -al /data to see the who owns the file and the permissions)
(perhaps also check if the directory has permission for that user to delete a file in it)
evanb said on Nov 1, 2004 at 12:06 PM :
I am using absolute paths and it does not let me delete a file. It appears as MX keeps this file active therefore when you try and del it it won't allow giving a message that the file is already in use.

This is happening when I try and delete application.log files from the cf server. Any ideas?
gpsguy101 said on Mar 17, 2005 at 9:57 AM :
I'm using CFFILE DELETE with Windows UNC path \\servername\fullpathSerdirectory\ in an application to MOVE and DELETE user files, COPY works fine using the UNS path, but both MOVE and DELETE give me an error stating Coldfusion can't DELETE or MOVE the files for an unknown reason. All the users have FULL CONTORL of the folders in question. How can I check to see if Coldfusion has user permission on the server???
No screen name said on Oct 10, 2005 at 4:43 AM :
Hi I get the same problem - cant delete for unknown reason.

I am trying to delete an XML file. Is there any restriction- do I have to specify the mimetype?

I am using the *same* path in my delete statement that I used for cffile action="read". File permissions are set to 777.
This is on a CFMX 7 LINUX system. Please macromedia give a tip other than "file/user permissions".

Thanks.
Francisco_Dublin said on Mar 24, 2006 at 8:27 AM :
The only way I was able to get around this was to store the fact I needed to remove the file in a varialbe (file name) and then at the end of my script when I redirected to another page I passed the variable in the URL.

On the page I redirected to I tested for the variable and if found deleted the file.

Still would be nice to delete the file on the same page though
Kapitaine said on Jan 8, 2007 at 3:50 PM :
If you want to delete a file you need the ABSOLUTE path on the machine holding the file itself.

For example:

c:\my_website.com\wwwroot\music\my_music_file.mp3

And in CFML:

<cffile action="delete" file="c:\my_website.com\wwwroot\music\my_music_file.mp3" />

As you can see this gives ColdFusion the exact location on the C drive of the computer/server holding the file.

The disk drive is important. After all, how would you expect ColdFusion to know where the file actually lives?

Thanks.

Michael Pumo.
morningdew77 said on Jun 6, 2007 at 7:54 AM :
I also have had trouble using the cffile delete function, even with absolute paths.

My issue turned out to be that the file was still locked by one of ColdFusion's threads. I had my cffile delete shortly after a cffile read for the same file.

The solution was simple, to make a delay in the script so that ColdFusion had enough time to finish the read thread. There are a few ways to accomplish this, I chose the following:
<cfset createObject("java", "java.lang.Thread").sleep(JavaCast("int", 5000))>
where 5000 is the number of milliseconds to delay.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6.1/htmldocs/tags-p30.htm