【问题标题】:Search Folders in ColdFusion 9在 ColdFusion 9 中搜索文件夹
【发布时间】:2012-06-21 01:37:42
【问题描述】:

我正在尝试创建一种搜索方法来在我的出站电子邮件中附加文件。我需要在文件夹中搜索并找到以某个字符开头的所有文件,然后将它们附加到电子邮件中。我只需要先了解如何创建这样的搜索方法,以便任何指向参考的指针或链接都将受到赞赏。

这是我目前所拥有的,但当我使用路径而不是 GetBaseTemplatePath() 时,它似乎无法正常工作

<cfscript>
  attributes.attachments = 2011093475839213;
</cfscript>

<cfset Directory = "E:\sites\Example.com\FileFolder\#attributes.attachments#"> 


<cfset CurrentDirectory=Directory>  
<cfset CurrentDirectory=ListDeleteAt(CurrentDirectory,ListLen(CurrentDirectory,"/\"),"/\")>  

<cfoutput>  
 <b>Current Directory:</b> #CurrentDirectory#  
    <br />  
</cfoutput>  

<cfdirectory action="list" directory="#CurrentDirectory#" name="result">  
<cfdump var="#result#"> 

当我稍微改变代码时

<cfset CurrentDirectory=GetBaseTemplatePath()> 

我的代码有效,我得到了当前目录中所有文件的列表。我的路上是否有我看不到的错误?

这是我的 CFMAIL 部分,我确实有问题。 当我转储我的#result# 查询时,我得到了文件夹中的所有文件。然后我得到这个错误:

The resource 2011093475839213.pdf was not found.

The root cause was: ''.

尽管有错误,但我确实收到了一封电子邮件,只是没有收到附件。

<!--- Email Test --->
<CFMAIL FROM="user1@example.com" TO="user2@example.com"  SUBJECT="Test" type="HTML">
<P> This is the attachment test</P>
<p> For this test to be successful, we need to receive some file attachments with this email</p>

    <cfloop query="result">

        <cfmailparam file="#result.name#" disposition="attachment">

    </cfloop>


</cfmail>
<!--- Email Test Ends --->

【问题讨论】:

  • 如果你这样做 &lt;cfdump var=#DirectoryExists(CurrentDirectory)# /&gt; 会发生什么?此外,您不需要 ListDeleteAt 的东西 - 使用 getDirectoryFromPath
  • 我设法用 DirectoryExists 绕过它,毕竟我的路径确实有错误。我会尝试使用 getDirectoryFromPath,因为当涉及到子目录时我会遇到一些问题
  • 我的cfmailparam 标记上出现错误The resource 2011093475839213.pdf was not found. The root cause was: ''. 我正在转储查询并且该文件确实存在。我不知道为什么给我这个错误。
  • 您没有指定目录。使用#result.directory#/#result.name#
  • @PeterBoughton 是的,错误是什么。谢谢

标签: coldfusion coldfusion-9


【解决方案1】:

cfdirectory 标签将允许您搜索具有特定模式的文件夹。使用它返回的查询,您可以遍历它并将您需要的所有文件附加到电子邮件中。

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f99.html

【讨论】:

  • 感谢您提供的链接,我会尝试并通知您。
【解决方案2】:

类似这样的:

<cfdirectory action="list" directory="#myDirectory#" name="myDir">

<cfmail subject="My Subject" to="yourAddress" from="myAddress">
  My Message
  <cfsilent>
    <cfloop query="myDir">
      <cfif Left(myDir.name,1) eq "Z">
        <cfmailparam file="#myDirectory & myDir.name#">
      </cfif>
    </cfloop>
  </cfsilent>
</cfmail>

【讨论】:

  • 要检查第一个字符,请改为使用left(mydir.name,1) EQ 'Z' - 尽管在这种情况下您甚至不需要这样做,因为您可以在 cfdirectory 标记上使用filter="Z*"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-03
  • 2012-07-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多