We help IT Professionals succeed at work.

Need VBScript to read a line that contains a program name and then look for it in a folder

Hello everyone.
Can I ask for some help ?
(I'd really REALLY be grateful for it.)

I have a file, C:\RayFile.txt".
This file contains a bunch of lines.
Interspersed within all the lines are a number of lines that contain the names of objects.
Here's an example of what one of those lines look like:
<file name="BLAnnWb4.ocx">

Now,  there is a folder, named "C:\RaysFolder", that is supposed to contain the actual object referenced by each <file name="????????.???"> line, inside of C:\RaysFiles.txt.

But sometimes, C:\RaysFolder is missing a file or two that have corresponding  <file name="????????.???"> lines (inside of C:\RaysFiles.txt).

I need a VBScript to read though the Ray.txt file for each occurrence of "<file name=".
Then using the value between the beginning and ending double quotes (IE:  BLAnnWb4.ocx), look to see if there is a file of the same name, in C:\RaysFolder.

If the file is missing from C:\RaysFolder, a dialog or something, indicating the same,  would be great.

I really do appreciate the help with this as I am not a VBScript expert and having such a script, would save me lots of time and help my eyesight as well.
(Cuz I do this process manually now.)

Thanks in advance for any and all efforts on my behalf.

Ray in Wisconsin
Comment
Watch Question

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Can you provide a sample rayfile.txt for test?

~bp
You bet !
Thanks fo considering this.
Ray.txt
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
If I understand you correctly, this should be pretty close, see what you think.

sInFile = "C:\RayFile.txt"
sBaseDir = "C:\RaysFolder\"

' Read entire input file into a single string variable
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFSO.OpenTextFile(sInFile)
sData = oInFile.ReadAll
oInFile.Close
Set oInFile = Nothing

' Create regular expression template to locae matches
Set oRegex = New RegExp
oRegex.Pattern = "<file name=""(.+)"">"
oRegex.IgnoreCase = True
oRegex.Global = True

' Loop through each match
For Each oMatch In oRegex.Execute(sData)
   If Not oFSO.FileExists(sBaseDir & oMatch.Submatches(0)) Then
      Wscript.Echo "Missing file: """ & sBaseDir & oMatch.Submatches(0) & """"
   End If
Next

Open in new window

~bp
Pretty close ?

It's PERFECT !
Absolutely PERFECT !

I can't thank you enough.
My eyes, can't thank you enough.

You’re the greatest.
Ray in Wisconsin  :)

Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Wow, that's about the best feedback ever, thanks so much, and so glad that solution worked out and is helpful.

~bp
I've requested that this question be closed as follows:

Accepted answer: 0 points for rkode's comment http:/Q_27427840.html#37071366

for the following reason:

If I could ward 1,000 points I would do it in an instant.<br /><br />Thanks you so VERY much.<br /><br />Ray in Wisconsin &nbsp;:)
I have been made aware that I selected an incorrect response as the solution.

I really wanted to select ID: 37070979 as the solution.

Can I request help in getting this addressed so that the points can be awarded and the incident closed ?

Thanks in advanced for anything that can be done.
I hope I can now close this incident.
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Thanks.

~bp
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Thank you rkode.  Much appreciated.

Rob.
You are more than welcome Rob.

I was so excited about getting Bill Prew's solution, that I kinda messed things up. (With regards to awarding points and closing the incident.)

Anyway, all is well now.

Ray in Wisconsin  :)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.