This tag is similar to the CFFILE ACTION= "READ" functionality, in that it reads from an ASCII file and returns the text for your use in ColdFusion templates. What's different is that this tag allows you to read in only part of a file at once, or just a single line of the file. It returns the text to you as a query rather than as a single text variable, which allows you to use convenient syntax in your code to refer to the file's contents in a line-by-line fashion.
Note: This tag was compiled using Delphi 4 and Vadim's DelphiCFX package. If you enjoy the tag's performance, consider trying these tools out yourself, or buy me a little gift of some kind, or both! :) -nate
Parameters
|
FILE |
Required. The full filesystem-style path to the text file. |
| NAME |
Required. The name of the query result set to put the file's contents into. Each line of the file will be a separate row in the query. So if NAME="MyQuery", then you could use QUERY= "MyQuery" in a CFOUTPUT tag to display the contents of the file. The query will always contain two columns:
|
| STARTROW |
Optional. Defaults to 1. The line number to start at. So if STARTROW= "10",the data in the 10th line of the file will be in the first row of the returned query. |
|
MAXROWS
|
Optional. If provided, provides the maximum number of lines that should be read in from the file. Useful if you have a very large file and don't want to read in the whole thing at once because it would take up too much of your system's resources. See example below. |
After the tag executes, the following variables will be populated for you:
Example
The following example demonstrates how to use STARTROW/MAXROWS and related variables to create a "data chunking" loop. The file is read in 10-line chunks. Each chunk of lines can be processed or output in whatever way you want, and the loop will execute as many times as needed until the end of the file is reached. Note that while this tag
is compatible with ColdFusion 2.0, this template wouldn't work because it would
result in multiple queries with the same name, which was not allowed in 2.0.
<CFSET File_StartRow = 1>
<CFSET File_ReachedEOF = "No">
<CFLOOP CONDITION="NOT File_ReachedEOF">
<CFX_FileReadLines
FILE="d:\CFUSION\BIN\cf40p.ini"
NAME="MyQuery"
MAXROWS="10"
STARTROW="#File_StartRow#">
<CFOUTPUT>
<P><B>Rows Read:</B> #File_LinesRead#<BR>
<B>ReachedEOF:</B> #File_ReachedEOF#<BR>
<B>StartRow:</B> #File_StartRow#<BR>
</CFOUTPUT>
<CFOUTPUT QUERY="MyQuery">
<LI> Row #CurrentRow#(#LineNum#): #Text#
</CFOUTPUT>
</CFLOOP>
This would cause something like the following to be displayed:
Rows Read: 10
ReachedEOF: NO
StartRow: 11
Rows Read: 10
ReachedEOF: NO
StartRow: 21
Rows Read: 10
ReachedEOF: NO
StartRow: 31
Rows Read: 4
ReachedEOF: YES
StartRow: 35