At one of the usergroup sessions this week someone asked if there was a way to get file information (size, date time, etc.) easily using a function. I said they should use
Which makes this a good opportunity to review some of the file i/o changes coming in Scorpio.
For starters, if you have ever had to work with large text files in ColdFusion (maybe parsing a large CSV file) you’ll know that doing so is very inefficient. You probably use code like this:
This is slow for two reasons. Not only does ColdFusion read the entire file into memory in a variable all at once, but also looping through the file requires treating it as a list which involves lots of parsing which can also be resource intensive.
Well, inefficient no more. In ColdFusion Scorpio you’ll be able to replace the above code block with this:
This code block open the file, reads one line at a time, and closes it when done. I actually used this myself recently in a ColdFusion code snippet that had to parse a massive tab delimited file, turning each line into a query row. Replacing the old
Oh, and although reading files line by line is the more common use case, you can also read by n characters at a time, like this:
In addition to the