Dave
Dave

Reputation: 987

Cffile action="write" adding empty lines into my txt

Using ColdFusion I am updating the top line of my txt file, however once I do this it adds an empty line after each line in my txt file and I have no idea why.

A breakdown of my code is as follows:

<!---CSV FILE--->
<cffile action="read" file="C:/ColdFusion10/cfusion/wwwroot/kelly2/debitorders.csv" variable="csvfile">

<cfoutput>
<!---LOOP THROUGH CSV FILE--->
<cfloop index="index" list="#csvfile#" delimiters="#chr(10)##chr(13)#">

        <!---SET VALUES--->           

       <!---TRIM VALUES--->

       <!---SET STRING LENGTH FOR EACH--->

       <!---SET TOTAL STRING--->



       <!---IF FILE FOR BANK EXISTS--->
        <cfif FileExists(ExpandPath("#listgetAt('#index#',5)#.txt"))>

            <!---READ EXISTING FILE HEADER--->
            <cffile action="read" file="C:/ColdFusion10/cfusion/wwwroot/kelly2/#bankname#.txt" variable="bankheader">
            <!---SPLIT UP THE HEADER TO ADD NEW VALUES ONTO IT--->
            <cfset numericvalue = listfirst(bankheader,chr(13))>
            <cfset numericvalue = #Right(numericvalue, 13)#>

            <cfset RecordCountvalue = #Left(numericvalue, 3)#>
            <cfset RecordCountvalue = #RecordCountvalue# + 1>
            <cfset RecordCountvalue = #NumberFormat(RecordCountvalue,"000")#>
            <cfset RecordCountvalue = #Left(RecordCountvalue, 3)#>
            <cfset RecordCountvalue = #RJustify(RecordCountvalue, 3)#>

            <cfset TotalRecordvalue = #Right(numericvalue, 10)#>
            <cfset TotalRecordvalue = (#TotalRecordvalue# + #amount#) * 100000>
            <cfset TotalRecordvalue = #NumberFormat(TotalRecordvalue,"0000000000")#>
            <cfset TotalRecordvalue = #Left(TotalRecordvalue, 10)#>
            <cfset TotalRecordvalue = #RJustify(TotalRecordvalue, 10)#>

            <!---SET HEADER FOR FILE--->
            <cfset fileheader_bank = "#UCase(bankname)#">
            <cfset fileheader_bank = "#Left(fileheader_bank, 15)#">
            <cfset fileheader_bank = "#LJustify(fileheader_bank, 16)#">
            <cfset newfile_header = "#fileheader_bank##RecordCountvalue##TotalRecordvalue#">

            <!---APPEND FILE AND ADD UPDATED HEADER--->
            <cfset bankheader = listSetAt(bankheader,1,"#newfile_header#","#chr(13)#")>
            <cffile action="write" file="#getDirectoryFromPath(getTemplatePath())#/#listgetAt('#index#',5)#.txt" output="#bankheader#">

            <!---APPEND FILE AND ADD NEW ENTRY--->
            <cffile action = "append"  
            file = "C:/ColdFusion10/cfusion/wwwroot/kelly2/#listgetAt('#index#',5)#.txt"  
            output = "#total_string#">

        </cfif>
</cfloop>
</cfoutput>

I am pretty sure the problem is in one of these cffile tags.

<!---APPEND FILE AND ADD UPDATED HEADER--->
                <cfset bankheader = listSetAt(bankheader,1,"#newfile_header#","#chr(13)#")>
                <cffile action="write" file="#getDirectoryFromPath(getTemplatePath())#/#listgetAt('#index#',5)#.txt" output="#bankheader#">

                <!---APPEND FILE AND ADD NEW ENTRY--->
                <cffile action = "append"  
                file = "C:/ColdFusion10/cfusion/wwwroot/kelly2/#listgetAt('#index#',5)#.txt"  
                output = "#total_string#">

I have removed a lot of the unnecessary but if you need any of it please let me know.

Upvotes: 0

Views: 964

Answers (1)

Jamin Quimby
Jamin Quimby

Reputation: 161

If you used CFScript you would not have the issue. Because your using ColdFusion Tags returns and spaces affect document layout. Try minifiying your code to remove any floating returns / spaces. I have run into this issue with creating PDF files in CF

Upvotes: 1

Related Questions