Skip to main content
April 18, 2008
Question

CFFILE questions

  • April 18, 2008
  • 4 replies
  • 281 views
I'm working with a file feed and my cffile is reading the file everyday.
I need to add codes to make sure a new file is in that directory and there is a file in the directory (to avoid reading no file and causing error) before my CFFILE read the file.
I'm not sure how can I do this and what to add, I'm new at CF.

I have this code:
<CFLOOP LIST="#mailList#" INDEX="i" >
<!--- Read the file --->
<CFFILE ACTION = "READ" FILE = "#MailFileName#" VARIABLE = "fileContents">
<!--- Call the function in the script above to create array --->
<CFSET parseFileContents( fileContents ) >
</CFLOOP>



This topic has been closed for replies.

4 replies

Inspiring
April 21, 2008
I'd start with cfdirectory.
Inspiring
April 18, 2008
BKBK
Community Expert
Community Expert
April 21, 2008
You're apparently talking about just one file. So test whether the file exists and, if so, whether there has been a change. See code sample below.

Assumptions:
1) MailFileName is an absolute path to the file.
2) The file name changes everyday, and is unique.
2) In OnApplicationStart or in Application.cfm, you have initialized the variable application.currentFile like this
<cfset application.currentFile = "absolute_path_to_file">

April 18, 2008
You could always trap the error and skip that e-mail address. See code below.
Inspiring
April 18, 2008
BYJ_wntrsnt wrote:
> I'm not sure how can I do this and what to add, I'm new at CF.
>

Take a peak at some ColdFusion documentation, if you don't have any -
the internet does, for 'File management tags' and ponder the
<cfdirectory ...> tag. See what that does for you.