Reading Text Files in WSH
(Page 1 of 4 )
No matter what type of scripting you do, it seems like you always have a need to work with text files. Whether you’re monitoring files or maintaining a log, reading and writing text files is a must. WSH is no different. It provides several methods for making your life easier. It even provides a few that you may not have expected. Let’s take a look.
Text files have many different uses: data storage, logging, and program configurations just to name a few. Sometimes this is done in an unformatted text file like a raw data dump or simple log file; sometimes it’s formatted like comma- and tab-delimited files; and sometimes it’s structured like INF files. In any of these cases, the one thing that remains the same is that we are working with plain text.
While the methods provided by WSH only allow us to work with plain text files, the use of third party controls can allow us to work with formatted files such as Microsoft Word documents.
Let’s begin by creating a plain text file to work with. We’ll create a sample data file that contains comma-delimited addresses. Each record is on a new line. For simplicity I’m not going to add a header record. Many files will include one. This is just a line that contains the title of each column.
John Doe,1 Main Street,New York
Jill Murphy,27 1/2 Broad Street,Miami
Jack Robertson,3245 Maple Ave.,San Francisco
Sam Jackson,165 S 134th Street,New Haven
Robert Smith,495 Rural Route 2,Knoxville
Now save your text file as C:\addresses.txt.
Next: Reading methods >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer