troubleshooting Question

How to store subfolder names in an array for later comparison -VBScript-

Avatar of SnAkEhIpS
SnAkEhIpSFlag for United States of America asked on
VB Script
5 Comments1 Solution1237 ViewsLast Modified:
The attached vbscript allows me to echo the base names of the top-level subfolders in the parent directory C:\Temp. I need to store them as elements of an array for comparison with a similar array. I have another script that I think will allow me to do the latter. How can I store the base names in an array?
'Enumerates all top-level folders by base name only, where the parent folder is C:\Temp

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

strFolderName = "C:\Temp"

Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")

For Each objFolder in colSubfolders
	strName =
	arrNames = Split(strName, "\")
	intIndex = Ubound(arrNames)

	Wscript.Echo arrNames(intIndex)

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros