Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Create fixed width using cffile

Community Beginner ,
Feb 24, 2009 Feb 24, 2009
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!
363
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 24, 2009 Feb 24, 2009
LATEST
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.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources