![]() |
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
|
|
How to use CFX_READTEXT - documentationAn alternative to the unwieldy Cold Fusion CFFILE tag - which can only be used to read whole files - this can scan text files line-by-line, or in blocks of lines.SUMMARYCFX_READTEXT is a small tag written in C/C++, but it addresses a very real issue - how to economically read text files into Cold Fusion. The existing CFFILE tag in Cold Fusion will read an entire file into memory - which is not a good idea for large files, particularly if the processing is taking place on a remote server. CONDITIONSCFX_READTEXT is freeware. As such, it may be freely distributed in the form of this zip file, provided this readme file is retained. All technical queries, bug reports etc. with regard to its use should be addressed to admin@albedo.co.uk. We'd, of course, appreciate it if you credited us/linked to us, but you know you don't have to. We'll be doing more stuff soon, so please do drop by our website at http://www.albedo.co.uk/ CFX_READTEXT is copyright ©Albedo Systems Ltd 2003-2004. INSTALLATIONThe zip file that contains this file should contain:
USAGEHere's an example, with all the attributes on separate lines to make it clear... (Bear in mind that not all of these parameters are mandatory). <CFX_ReadText filename="c:\websites\mysite\myfile.txt" firstline="100" lastline="200" delimiter="|" filestats="Y" > All text between the firstline and the lastline attributes is returned in Cold Fusion as a list variable #cfxLine# with the delimiter specified (the delimiter defaults to Ascii 13 - carriage return). Other file information is returned, some of which is only meaningful if filestats="Y". Here is a list of returned information:
[SAMPLE CODE BEGINS] <cfset filepath="c:\websites\mysite\myfile.txt"> <cfset filepath=ReplaceNoCase(filepath, "\", "/", "ALL")> <cfset delim=Chr(13)> <cfset first_line="100"> <cfset last_line="200"> <!--- Pretty obvious params, except for filestats... ---> <!--- This is just an added extra, which reads all the way through ---> <!--- The file to give a total line count and file size ---> <!--- Defaults to No, since it's a waste if not needed ---> <!--- Oh, and delimiter is used in the list output as a separator ---> <CFX_ReadText filename="#filepath#" firstline="#first_line#" lastline="#last_line#" delimiter="#delim#" filestats="Y" > <!--- firstline defaults to 1 lastline defaults to 1 delimiter defaults to Chr(13) (CR) filestats defaults to N ---> <cfif cfxfiletype EQ 1> <cfset fileformat="PC"> <cfelseif cfxfiletype EQ 2> <cfset fileformat="Unix"> <cfelseif cfxfiletype EQ 3> <cfset fileformat="Mac"> <cfelse> <cfset fileformat="unknown file format"> </cfif> <!--- Again, pretty obvious output params ---> <!--- The EOF character is -1 if EOF is passed, zero otherwise ---> <!--- The actual full line data is passed as a delimited list ---> <!--- using the delimiter input earlier ---> <!--- LinesReturned is the actual figure - this may be less than ---> <!--- expected, due to EOF being encountered ---> File Format: <cfoutput>#fileformat#<br></cfoutput> Total lines in file: <cfoutput>#cfxLineCount#<br></cfoutput> Total characters in file: <cfoutput>#cfxCharCount#<br></cfoutput> EOF Indicator: <cfoutput>#cfxEOF#<br></cfoutput> Lines Returned: <cfoutput>#cfxLinesReturned#<br></cfoutput> Characters Returned: <cfoutput>#cfxCharsReturned#<br></cfoutput> <br> <cfset LineCt=ListLen(cfxLine,delim)> <cfset LineArray=ListToArray(cfxLine,delim)> <cfloop index = "LoopCount" from = "1" to = "#cfxLinesReturned#"> <cfset LineNo=LoopCount+first_line-1> <cfoutput><b>#LineNo#:</b> #LineArray[LoopCount]# </cfoutput><br> </cfloop> [SAMPLE CODE ENDS] OTHER ALBEDO TAGSIf you liked this, check out our CFX_FONT tag, downloadable from http://www.albedo.co.uk/goodies/cfusion.cfm. It allows you to create masses of anti-aliased text graphics and has oodles of options. Use and enjoy. Fin Fahey Fiona Daly LEGAL DISCLAIMERNeither Albedo Systems Ltd. nor anyone else who has been involved in the creation, production or delivery of this product shall be liable for any direct, indirect, consequential or incidental damages (including damages for loss of business profits, business interruption, loss of business information, and the like) arising out of the use or inability to use this product even if Albedo Systems Ltd. has been advised of the possibility of such damages. CFX_READTEXT is copyright ©Albedo Systems Ltd 2003-2004. |