Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to search a folder to find all sub-folders with "spec" in the name?

Posted on 2013-01-25
1
Medium Priority
?
371 Views
Last Modified: 2013-02-25
I need to search in a folder for other folders that has "spec" in the folder name.  Below is what I have so far.  I figured out how to search the entire drive but I want to specify a specific folder("d:\eng")

Thanks

Set objRegEx = CreateObject("VBScript.RegExp")

objRegEx.Global = True   
objRegEx.IgnoreCase = True
objRegEx.Pattern = "backup"
strComputer = "." 

Set objFileToWrite = CreateObject("Scripting.FileSystemObject").OpenTextFile("d:\\temp\\listfile.txt",2,true)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory Where Drive = 'e:'")


For Each objFolder in colFolders
    strFolder = objFolder.FileName
    Set colMatches = objRegEx.Execute(strFolder)
    If colMatches.Count > 0 Then
        objFileToWrite.WriteLine(objFolder.Name)
    End If
Next 
objFileToWrite.Close
Set objFileToWrite = Nothing
Wscript.Echo "End"

Open in new window

0
Comment
Question by:GreyHippo
1 Comment
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 38821101
You should be able to just adjust the WMI query to specify what you want, like this:

Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory Where Drive = 'd:' And Path = '\\eng\\' And Name Like '%spec%'")

Open in new window

~bp
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question