Solved

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

Posted on 2013-01-25
1
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 56

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

624 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