Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript - Lists subfolders or a subfolder

Status
Not open for further replies.

JCMILBURN

IS-IT--Management
Sep 25, 2002
5
US
Hoping that someone can help me out with this.

Here is what I got.

I have a mapped network Drive called J: and I need to list all of the subfolders and their child subfolders for the J drive and dump that into an array.

I can list all of the subfolders of the root drive but not the child subfolder for the subfolders.

Here's the code that I have that lists the subfolders but not their child subfolders

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

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

For Each objFolder in colSubfolders
Wscript.Echo objFolder.Name
Next

Does someone know of another way to do this or will I have to do a for each loop to get the child folders???

ThanX
 
search the forum for recurse or resursive. There is probably an FAQ on this as well.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

Alternately you can use the FileSystemObject and like EBGreen, you should be able to find examples of that in this forum.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top