Solved

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

Posted on 2013-01-25
1
357 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 54

Accepted Solution

by:
Bill Prew earned 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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