Search code examples
coldfusioncoldfusion-9

ColdFusion could not delete the file for an unknown reason


I am trying to delete and recreate a test file, but am getting the error below. Can anyone tell me why this is happening?

Error:

ColdFusion could not delete the file e:\sample\test2.html for an unknown reason.

Code:

<cfif FileExists("e:\sample\test2.html")>
   <cffile action="delete"file="e:\sample\test2.html"><br>
   <p>deleted the file </p>
<cfelse>
   <p>Sorry, can't delete the file - it doesn't exist.</p>
</cfif>

<cfset createObject("java", "java.lang.Thread").sleep(JavaCast("int", 90000))>
<cfsavecontent variable="HTML">
    <cfinclude template="noticeEmail.cfm">
</cfsavecontent>        

<cffile action="WRITE"  attributes = "normal" nameconflict="Overwrite"  
      file="e:\sample\test2.html" output="#HTML#">

Solution

  • The first thing I would check is permissions for the user that ColdFusion is running as.
    I don't know how you're running CF or in what sort of environment you're on but assuming that this is a local development environment, are on a windows machine and are running ColdFusion as a service:

    • Find the ColdFusion service in the services manager (start -> run -> services.msc)
    • Right click on the ColdFusion Service and look in the log on tab to find "who this is running as. (the service could be named several things depending on how it is installed but look for "ColdFusion 9 Application Server", Anything starting with JRun or Macromedia)
    • If this isn't local system then you'll need to confirm that the user has read / write access to e:\sample\test2.html

    Other things that could cause errors, could another program have this file locked, what is happening with the file after it is created (is it only created through ColdFusion)

    Also could you post the actual error that you are receiving?
    If it's "Sorry, can't delete the file - it doesn't exist." Then this is due to the check you've got at the top to confirm if the file exists.

    Finally the code that you've pasted above appears to have the first character missing from every line, it would be worth fixing this so that others can more easily copy and paste the code.