ColdFusion无法删除文件,原因不明

时间:2012-04-17 08:30:06

标签: coldfusion coldfusion-9

我正在尝试删除并重新创建测试文件,但我收到以下错误。谁能告诉我为什么会这样?

错误:

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

代码:

<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#">

4 个答案:

答案 0 :(得分:2)

我要检查的第一件事是ColdFusion正在运行的用户的权限。
我不知道你是如何运行CF的,或者你在什么样的环境中,但假设这是一个本地开发环境,是在Windows机器上运行ColdFusion作为服务:

  • 在服务管理器中找到ColdFusion服务(开始 - &gt;运行 - &gt; SERVICES.MSC)
  • 右键单击ColdFusion服务并查看登录选项卡,找到“这是谁正在运行。”(根据安装方式,该服务可以命名为几个但是 寻找“ColdFusion 9 Application Server”,一切都以 JRun或Macromedia)
  • 如果这不是本地系统,那么您需要确认用户是否具有对e:\ sample \ test2.html
  • 的读/写权限

其他可能导致错误的事情可能是另一个程序锁定了这个文件,文件创建后发生了什么(只是通过ColdFusion创建)

您也可以发布您收到的实际错误吗? 如果它是“抱歉,无法删除该文件 - 它不存在。”然后这是由于你在顶部检查确认文件是否存在。

最后,您粘贴在上面的代码似乎每行都缺少第一个字符,因此值得修复,以便其他人可以更轻松地复制和粘贴代码。

答案 1 :(得分:0)

您可以使用此代码删除带有ColdFusion的MS Word文档

<cfif FileExists( WordFilePath &".doc")>
   <cffile action="delete"
       file="#WordFilePath#.doc">
<cfelse>
    Sorry, can't delete the file - it doesn't exist.
</cfif>

答案 2 :(得分:0)

您的网络服务器/操作系统可能正在保留该文件。你可以尝试创建文件而不打开它,看看你是否删除它?所以只需创建一个文件,然后立即删除它。

答案 3 :(得分:0)

我遇到了同样的问题,但我找到的答案都没有应用。虽然我的文件通过了FileExists测试,但它仍然无法实际删除。我正在使用变量构建文件名:

<cfset sFilename = REQUEST.SubscriberWebFiles
                        & form.SubscriberID & "\Attachments\" 
                        & qryAttachmentsTrash.AttachmentName>

我用Trim包装了代码:

<cfset sFilename = Trim(REQUEST.SubscriberWebFiles
                       & form.SubscriberID & "\Attachments\" 
                       & qryAttachmentsTrash.AttachmentName)>

这个问题神奇地消失了!