Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..
SYS-CON.TV
Today's Top SOA Links


Ben Forta's Blog - Scorpio File I/O Enhancements
We did indeed add a new function to Scorpio called GetFileInfo() which returns a structure

Ben Forta's Blog

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 <CFDIRECTORY>, but afterwards remembered that we did indeed add a new function to Scorpio called GetFileInfo() which returns a structure containing:

  • canread
  • canwrite
  • ishidden
  • lastmodified
  • name
  • parent
  • path
  • size
  • type

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:

<!--- Read entire file --->
<cffile action="read"
   file="#fileName#"
   variable="myFile">

<!--- Loop through file variable one line at a time --->
<cfloop list="#myFile#"
   index="line"
   delimiters="#chr(10)##chr(13)#">

   <!--- Do stuff with line here --->
   ...
</cfloop>

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:

<!--- Loop through file one line at a time --->
<cfloop file="#fileName#"
   index="line">

   <!--- Do stuff with line here --->
   ...
</cfloop>

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 <CFFILE> <CFLOOP> with a new <CFFILE FILE=> cut down processing time from several minutes to under 10 seconds.

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:

<!--- Loop through file 100 characters at a time --->
<cfloop file="#fileName#"
   index="chars"
   characters="100">

   <!--- Do stuff with line here --->
   ...
</cfloop>

In addition to the <CFLOOP> enhancements, we've also added lots of new file i/o functions that you can use to access and manipulate files directly. The new functions include:

  • FileClose()
  • FileCopy()
  • FileDelete()
  • FileIsEOF()
  • FileMove()
  • FileOpen()
  • FileRead()
  • FileReadBinary()
  • FileReadLine()
  • FileSetAccessMode()
  • FileSetAttribute()
  • FileSetLastModified()
  • FileWrite()
  • GetFileInfo()
  • IsImageFile()
  • IsPDFFile()

About Ben Forta
Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

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, but afterwards remembered that we did indeed add a new function to Scorpio called GetFileInfo() which returns a structure containing:


Your Feedback
ColdFusion News wrote: 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, but afterwards remembered that we did indeed add a new function to Scorpio called GetFileInfo() which returns a structure containing:
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE