Web News

T-Systems selects Eutelsat's Eurobird 9 Satellite
Media&Broadcast, a business unit of T-Systems and a service provider in Europe, and Eutelsat Communications, have signed a 10-year agreement...

Microsoft teams with Siemens VDO Automotive
Microsoft Corp. said Friday it will work with Germany's Siemens VDO Automotive AG on a line of communication, information, entertainment and navigation products for vehicles. The deal extends...

Germany's Deutsche Telekom eyeing Aussie...
Deutsche Telekom has expressed interest in setting up a high-speed glass fiber network in Australia, a Financial Times report said. The Financial Times report...


09.07.07


ColdFusion 8: Reading The Top (or Another Slice) Of A File

By Raymond Camden

In the ColdFusion IRC channel today, someone asked about reading just the top portion of a file.

While she was looking for a command line solution and not ColdFusion, I thought it would be interesting to share how easy it is in ColdFusion 8 using the new file attribute to CFLOOP.

This code will loop over the first ten lines of a file and display them:



I first create a variable to point to my server.log file. I then create a counter variable "c". Then I simply use the file attribute for cfloop to loop over the file. When I hit 10 lines, I break.


No matter how big the file is, this code will run extremely fast as it won't need to parse in the entire file. My server.log file could be 10 gigs and this would still run quickly.

But wait - it gets betteer. TJ Downes pointed out that you can provide a FROM and TO and the tag will actually display a slice, or portion, of the file. This is not documented as far as I know. The following code is shorter and equivalent to the earlier listing:



One thing to watch out - if you try to read beyond the size of the file, you will get an error. In that case, the first listing would be safer as it would support a file of any size.

Comments


About the Author:
Raymond Camden, ray@camdenfamily.com
http://ray.camdenfamily.com

Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy.

About DevWebProDE
DevWebProDE is for professional developers ... those who build and manage applications and sophisticated websites. DevWebProDE delivers via news and expert advice New Strategies In Development.

DevWebProDE is brought to you by:

SecurityConfig.comNetworkingFiles.com
NetworkNewz.comWebProASP.com
DatabaseProNews.comSQLProNews.com
ITcertificationNews.comSysAdminNews.com
LinuxProNews.comWirelessProNews.com
CProgrammingTrends.comNetworkNewz.com



-- DevWebProDE is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
 © 2007 iEntry Inc.  All Rights Reserved  Privacy Policy Legal    

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


New Strategies In Development DevWebProDE News Archives About Us Feedback DevWebProDE Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact