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
Solved

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

Posted on 2013-01-25
1
354 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 53

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

792 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