Skip to main content
Inspiring
August 28, 2008
Answered

cfloop over a file - set start point?

  • August 28, 2008
  • 3 replies
  • 553 views
CF8 - I'm using cfloop to read a file, as described in the documentation:

<cfloop
index = "index name"
file = "absolute path and filename">
</cfloop>

It's a text file; is there a way to define lines? Like start reading at line 4000?

Thanks if anyone knows!
    This topic has been closed for replies.
    Correct answer phamm
    I think I found the answer here.

    http://coldfused.blogspot.com/2007/07/new-file-io-in-coldfusion-8.html

    3 replies

    Inspiring
    August 29, 2008
    Both techniques would work. I have not done much work with the new file objects. But the difference seems to be whether the entire file is read into memory at once or only portions of it. For large files, the technique in the blog entry would be a better fit. Because it works with smaller chunks of information. I do not know if it makes a difference with smaller files.

    From: http://coldfused.blogspot.com/2007/07/new-file-io-in-coldfusion-8.html
    With cfloop, you can also iterate over a part of the file by specifying "from" and "to" values. Here is an example to loop over lines between 10 and 20.
    <cfloop file="c:\temp\myfile.txt" index="line" from=10 to=20>
    <cfoutput>#line#</cfoutput> <!--- or do whatever with the line --->
    </cfloop>
    phammAuthor
    Inspiring
    August 29, 2008
    Thanks all!!!!

    Since I am dealing with large files (500K+lines), I'm going to use the "from=" option. It's frustrating that this option is not in the Cold Fusion 8 "cfloop" documentation, particularly since better file handling in cfloop is one of the major new features in cf8! I wonder how many other undocumented features are out there for cold fusion? Is this the tip of the iceberg?
    Inspiring
    August 28, 2008
    I didn't read your link, but my method would be to treat the file as a list separated by chr(10) & chr(13).
    phammAuthorCorrect answer
    Inspiring
    August 28, 2008