Link to home
Start Free TrialLog in
Avatar of Whah
Whah

asked on

Searching for dates within a text file

I am working on a program that will scroll through text files within a directory tree searching for a date.  The main problem that I am having is that this date can appear on different lines in the file and it is not always the first thing on the line.  I need to read in the value and set a variable with it for use later in the program.

Any help will be appreciated.  Thanks,
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

You would have to use the FSO to read the text file(s) into each of there own array(s) within a for next loop and then from there have an if statement to check each array against the date you are looking for.

www.juicystudio.com is a good starting place to research and use the FSO, you will need a reference to the Microsoft Scripting Runtime :) You can do this by going to Project --> References and checking the one called Microsoft Scripting Runtime ;)

I can post back an example later on if you would like for one text file, however searching through more then one text file is probably going to be more complex because you would also then need to store each of the text file names to be searched through before you can even begin the search :)
ASKER CERTIFIED SOLUTION
Avatar of Bob Lamberson
Bob Lamberson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Enabbar Ocap
If you're looking for any date, not just a specifis one then IsDate ("poss_date_string") will return true if the "poss_date_string" can be converted to a date.
At least if you get False then you know that it can't be. You will need further sanity checking to ensure that is is a sensible date, say within a time period that you are expecting.  
Avatar of [ fanpages ]
[ fanpages ]

Hi Whah,

What format will the date be in?

e.g. dd/mm/yyyy
or ddd-mmm-yy
or m/d/yyyy
or possibly any valid data format?

Also, is there a limit to the records of the file in which the date will reside?  i.e. if it's not in the first 5 rows of the file, then it isn't there.  Or is there *always* a date in the file regardless of it's position?

Thanks for your clarification.

BFN,

fp.
Avatar of Whah

ASKER

Thanks everyone for the help on this question.  We are going to approch it in a little different manner, but thank you for your help anyway.
Sorry we didn't get to discuss further to offer alternative methods.

BFN,

fp