Skip to main content
Participant
February 24, 2009
Question

Create fixed width using cffile

  • February 24, 2009
  • 1 reply
  • 383 views
Hello All.

I am trying to use <cffile> to output the results of a <cfquery> to a fixed width text file for input to a batch program. A space in column one of the output file is required, but have yet to determine a solution that allows a space in column one. Any help is vastly appreciated!

Thanks William!
    This topic has been closed for replies.

    1 reply

    Inspiring
    February 24, 2009
    Just put the space in the output! <cffile ...> wil write it.

    <cfsaveContent variable="exampleOne">
    1A3B35
    2E3G64
    3L4P10
    </cfsaveContent>
    ^
    |
    note the blank space at the beginning of each line.

    <cffile action="write" file="path/to/file.txt" output="#exampleOne#">

    OR

    <cfloop query="myQuery">
    <cfset record = " #myQuery.aCol##myQuery.bCol##myQuery.cCol#">

    <cfif myQuery.currentRow EQ 1>
    <cffile action="write file="path/to/file.txt" output="#record#">
    <!--- create file and first line of data --->
    <cfelse>
    <cffile action="append" file="path/to/file.txt" output="#record#">
    <!--- add each additional record to existing file --->
    </cfif>
    </cfloop>

    OR

    <cfloop query="myQuery">
    <cfif myQuery.currentRow EQ 1>
    <cffile action="write file="path/to/file.txt"
    output=" #myQuery.aCol##myQuery.bCol##myQuery.cCol#">
    <!--- create file and first line of data --->
    <cfelse>
    <cffile action="append" file="path/to/file.txt"
    output=" #myQuery.aCol##myQuery.bCol##myQuery.cCol#">
    <!--- add each additional record to existing file --->
    </cfif>
    </cfloop>



    That is a couple of possible ways to do it, but the important point is
    that <cffile...> is going to write anything and everything in the
    output=""> parameter, including white spaces.