I was thinking something along these lines... <cfset lineDelimiter=chr(10)> <cfset columnDelimiter=","> <cfset fileName="addressFile.csv">
<cftry> <cffile action="READ" file="#filename#" variable="addressFile"> <cfset errorCount=0> <cfloop index="row" list="#addressFile#" delimiters="#lineDelimiter#"> <cfif listLen(row,columnDelimiter) eq expectedColumns and row neq ""> <!--- Good stuff here. ---> <cfelseif row eq ""> <!--- This row is completely blank. It might be at the end... ---> <cfelse> <cfset errorCount=errorCount+1> <!--- Throw an error that this row is wrong? ---> <!--- Count the number of bad rows? ---> <!--- Keep going or bail after first? ---> <!--- List all the errors with their line numbers? ---> <cfbreak> </cfif> </cfloop> <cfcatch> Something threw an error...(it really broke). </cfcatch> </cftry> <cfif errorCount gt 0> No can do, the file has some issues. Please fix it and try again. </cfif> Jerry Johnson >>> [EMAIL PROTECTED] 01/07/03 11:21PM >>> Thanks Jerry - I wonder if you or someone on the list can confirm what I am thinking. <cfoutput>#ListLen(AddressFile, ",")#</cfoutput> returns 1. I suspect that its because the file I've been provided with is not truly a CSV file (sample below). I've tried interrogating it for a carriage return but that returns the same value. TIA! Someones Name,theireemail@address Someones Name,theireemail@address Someones Name,theireemail@address Someones Name,theireemail@address ********** Kevin Parker Web Services Manager WorkCover Corporation [EMAIL PROTECTED] www.workcover.com p: 08 82332548 f: 08 82332000 m: 0418 806 166 ********** -----Original Message----- From: Jerry Johnson [mailto:[EMAIL PROTECTED]] Sent: Wednesday, 8 January 2003 9:01 AM To: CF-Talk Subject: Re: Test CSV First, wrap the read and processing in a <cftry>, so that even if the data is bad, you won't break. Next, you might want to create a little CF app that reads the file and looks for patterns, and if an error is thrown, stops the processing. for the error checking, a simple listlen() for each line could get you there. (if there are five columns, the listlen should ALWAYS be 5, right?) Jerry Johnson >>> [EMAIL PROTECTED] 01/07/03 05:27PM >>> I have a CSV file that I want to read into variable (see below). Before doing so I think I should test the construction of the file to ensure that its valid otherwise I think there is a risk of the process falling over if it encounters a badly constructed file somewhere a long the way. How can I test that a file is a validly constructed CSV file. It will contain e-mail addresses exported from ACT. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Get the mailserver that powers this list at http://www.coolfusion.com Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4