Solved

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

Posted on 2013-01-25
1
351 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 51

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now