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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBS - How to read file contents

Reply to Message Icon

Name: jej1216
Date: August 9, 2006 at 15:13:03 Pacific
OS: Windows Server 2003
CPU/Ram: Intel Xeon 3.00 GHz
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: StreamLogic
Date: August 9, 2006 at 18:24:48 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBS - How to read file contents

read file content using batch loop www.computing.net/answers/programming/read-file-content-using-batch-loop/17010.html

how to read xls file in delphi www.computing.net/answers/programming/how-to-read-xls-file-in-delphi/19316.html

How to read bit in C www.computing.net/answers/programming/how-to-read-bit-in-c/10123.html