Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search machine.config's 1

Status
Not open for further replies.

mastermindg

IS-IT--Management
Jan 28, 2009
7
This is similar to this post:


I've written a script that will search a machine.config for various strings. It has just occurred to me that there might be varying installs of .NET Framework.

This is what I need to do:

Search under C:\WINDOWS\Microsoft.NET\Framework\ for
directories starting with v (v*) for each
directory matching above ($directory)
opentextfile $directory/config/machine.config

What is the correct syntax to accomplish this?
 
I have created a script that successfully searches a single text file and outputs a regex match. What I am need assistance with is searching MULTIPLE text files in .NET Framework directories, rather than creating multiple statements for each possible iteration.
 
So, I guess you want to use the Subfolders collection.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK, this is what I have so far:

Set filesys = CreateObject("Scripting.FileSystemObject")
Set winPath = filesys.GetSpecialFolder(0)
strPath = winPath & "\Microsoft.NET\Framework"
Set folder = filesys.GetFolder(strPath)
Set sfolder = folder.SubFolders

For Each f1 in sFolder
If Left(f1.Path,12) = strPath & "\v" Then
s = s & f1.name
s = s & vbCrLfc
End If
Next
wscript.echo s

The problem is that it's not returning anything.
 
I figured it out, I wasn't accounting for all the characters in the path:

Set filesys = CreateObject("Scripting.FileSystemObject")
Set winPath = filesys.GetSpecialFolder(0)
strPath = winPath & "\Microsoft.NET\Framework"
Set folder = filesys.GetFolder(strPath)
Set sfolder = folder.SubFolders

For Each f1 in sFolder
If Left(f1.Path,36) = strPath & "\v" Then
s = s & f1.name
s = s & vbCrLfc
End If
Next
wscript.echo s
 
I'd replace this:
If Left(f1.Path,36) = strPath & "\v" Then
with this:
If Left(f1.Name,1) = "v" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for that.

It does make more sense to use the folder name rather than path. I was going to create an if...else statement to handle different path lengths but this is so much simpler.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top