2012-06-19 56 views
0

我想創建一個搜索方法來附加我的出站電子郵件上的文件。我需要在一個文件夾內搜索並找到所有以特定字符開頭的文件,然後將它們附加到電子郵件中。我只需要一個關於如何創建這樣的搜索方法的先行先導,以便任何指向引用的指針或鏈接都將受到讚賞。在ColdFusion中搜索文件夾9

這是我有什麼事這麼遠,但它似乎沒有工作正確的,當我使用一個路徑,而不是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="[email protected]" TO="[email protected]" 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 ---> 
+1

會發生什麼,如果你做''? 此外,你不需要'ListDeleteAt'東西 - 使用['getDirectoryFromPath'](http://cfdocs.org/getdirectoryfrompath) –

+0

我設法繞過它與DirectoryExists,我確實有一個錯誤,我的路徑畢竟。我將嘗試使用getDirectoryFromPath,因爲在涉及子目錄時我遇到了一些問題 – Geo

+0

我在我的'cfmailparam'標籤上收到錯誤,指出找不到資源2011093475839213.pdf。 根本原因是:''。' 我正在傾銷查詢並且該文件確實存在。我不知道爲什麼給我錯誤。 – Geo

回答

1

事情是這樣的:

<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> 
+2

要檢查第一個字符,請執行'left(mydir.name,1)EQ'Z'',儘管在這種情況下,您甚至不需要這樣做,因爲您可以在該處執行'filter =「Z *」' cfdirectory標記。 –

+0

不知道過濾器標籤,謝謝。 –