rragledavis
asked on
Extra carriage return in <cffile> created tab delimited text file
I have created a script that converts a number of records in a database to a tab delimited text file and emails the file to the person who needs to import it into their own database. This was working a few weeks ago and some minor change (?) has caused it to regularlt return a file that adds an extra blank line between each record. I have poured over this code, viewed it in a text editor to see hidden characters, removed the hard return and substituted <cfset newline=Chr(13& Chr(10> and then used #newline# instead of the hard return. Here is the current code: (not including the query and with email addresses removed)
I am stumped.
<cfsetting enablecfoutputonly="yes">< /head><bod y><cfsavec ontent variable="admissions_file" ><cfloop query="freshman"><cfoutput >"#Title#" "#Name#" "#Middle#" "#Last#" "#Address#" "#Address2#" "#City#" "#State#" "#Zip#" "#Country#" "#Email#" "#Interest#" "#Year#" "#Date#" "#ID#" "#Trim(Degree)#"
</cfoutput></cfloop></cfsa vecontent> <cfoutput> <cffile action="write" output="#admissions_file#" file="filepath\freshman.#D ateFormat( Now(),'mmd dyy')#.txt " nameconflict="overwrite"> </cfoutput><cfmail from="email@email.com" to="email@email.com" cc="email@email.com" subject="freshman.#DateFor mat(Now(), 'mmddyy')# .txt" mimeattach="filepath\fresh man.#DateF ormat(Now( ),'mmddyy' )#.txt">Yo ur freshman catalog requests</cfmail>
I am stumped.
<cfsetting enablecfoutputonly="yes"><
</cfoutput></cfloop></cfsa
ASKER
Just tried and this just resets the value of admissions_file over and over until the last field of the last record so my data set ends up UG? Oh well. . .
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hmm, if it consistently adds a blank line, could you just depend on that and take out your carriage return and use the one it's adding?
Like this:
<cfsetting enablecfoutputonly="yes">< /head><bod y><cfsavec ontent variable="admissions_file" ><cfloop query="freshman"><cfoutput >"#Title#" "#Name#" "#Middle#" "#Last#" "#Address#" "#Address2#" "#City#" "#State#" "#Zip#" "#Country#" "#Email#" "#Interest#" "#Year#" "#Date#" "#ID#" "#Trim(Degree)#"</cfoutput ></cfloop> </cfsaveco ntent>
Personally, I'd do this instead:
<cfset filename="filepath\freshma n.#DateFor mat(Now(), 'mmddyy')# .txt">
(if you need the first line to have field names)
<cfset headers="Title Name Middle Last Address Address2 City State Zip Country Email Interest Year Date ID Degree">
<cffile action="WRITE" file="#filename#" output="headers" addnewline="Yes">
then the content
<cfloop query="freshman">
<cfset outputLine="#Title# #Name# #Middle# #Last# #Address# #Address2# #City# #State# #Zip# #Country# #Email# #Interest# #Year# #Date# #ID# #Degree#"> <!--- where the whitespace is the single tab delimiter. --->
<cffile action="APPEND" file="#filename#" output="outputLine" addnewline="Yes">
</cfloop>
Like this:
<cfsetting enablecfoutputonly="yes"><
Personally, I'd do this instead:
<cfset filename="filepath\freshma
(if you need the first line to have field names)
<cfset headers="Title Name Middle Last Address Address2 City State Zip Country Email Interest Year Date ID Degree">
<cffile action="WRITE" file="#filename#" output="headers" addnewline="Yes">
then the content
<cfloop query="freshman">
<cfset outputLine="#Title# #Name# #Middle# #Last# #Address# #Address2# #City# #State# #Zip# #Country# #Email# #Interest# #Year# #Date# #ID# #Degree#"> <!--- where the whitespace is the single tab delimiter. --->
<cffile action="APPEND" file="#filename#" output="outputLine" addnewline="Yes">
</cfloop>
ASKER
pmascari That worked. Wonderful!
8riaN I had either a choice of two carriage returns or none. Either one continuous record or a blank between each record so couldnt count on one being added
8riaN I had either a choice of two carriage returns or none. Either one continuous record or a blank between each record so couldnt count on one being added
Maybe something like this will work instead:
<cfset admissions_file= "">
<cfloop query="freshman">
<cfset admissions_file= "#Title#" & chr(9)>
<cfset admissions_file= "#Name#" & chr(9)>
<cfset admissions_file= "#Middle#" & chr(9)>
<cfset admissions_file= "#Last#" & chr(9)>
<cfset admissions_file= "#Address#" & chr(9)>
<cfset admissions_file= "#Address2#" & chr(9)>
<cfset admissions_file= "#City#" & chr(9)>
<cfset admissions_file= "#State#" & chr(9)>
<cfset admissions_file= "#Zip#" & chr(9)>
<cfset admissions_file= "#Country#" & chr(9)>
<cfset admissions_file= "#Email#" & chr(9)>
<cfset admissions_file= "#Interest#" & chr(9)>
<cfset admissions_file= "#Year#" & chr(9)>
<cfset admissions_file= "#Date#" & chr(9)>
<cfset admissions_file= "#ID#" & chr(9)>
<cfset admissions_file= "#Degree#" & chr(10)>
</cfloop>
<cffile action="write" output="#admissions_file#"