Computing.Net > Forums > Programming > VBS - How to read file contents

VBS - How to read file contents

Reply to Message Icon

Original Message
Name: jej1216
Date: August 9, 2006 at 15:13:03 Pacific
Subject: VBS - How to read file contents
OS: Windows Server 2003
CPU/Ram: Intel Xeon 3.00 GHz
Model/Manufacturer: Dell
Comment:

I need to add to an existing VBS script - to read the contents of a CSV file and locate specific data, then the check the date to see if it matches the current date. Based on what it finds, it needs to send an email. I have the Sub written to send the email, but I don't know how to read the CSV file to locate the text.

This is my first foray into VBS scripting - I'm looking for sample code, suggested refrences/groups, etc.

TIA,

Joe


Report Offensive Message For Removal


Response Number 1
Name: StreamLogic
Date: August 9, 2006 at 18:24:48 Pacific
Subject: VBS - How to read file contents
Reply: (edit)

Joe,

Your best bet here is to use the FileSystemObject to open a file, parse it, then perform your functions once you find the relevant data.

You will want to use the OpenTextFile method to open the CSV file. This returns a TextStream object. On this TextStream object, you can call the .ReadAll or .ReadLine method. These will read the data into the TextStream object. You can then search this data using vaious methods such as InStr(), etc.

An alternative would be to use the XML DOM to load the CSV into an XML object, then use XPath to search certain sections which contain the data you are looking for. You can map columns to nodes in the XML, etc.

FSO reference: http://www.tutorial-web.com/asp/fso/

XML Reference: http://www.devguru.com/Technologies/xmldom/QuickRef/xmldom_intro.html

You may also want to search for "CSV to XML code" for examples on the web. I have done this many times and would be happy to provide sample code on both methods mentioned above if you email me.

Hope this points you in the right direction.


Curtis Hughes
StreamLogic Inc.
http://www.streamlogicinc.com


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: VBS - How to read file contents

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge