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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject Folders

Status
Not open for further replies.

butler

MIS
Oct 12, 1998
88
US
Hi all,

The following code prints folder names a collection of 'folders'...

Dim fso As New FileSystemObject
Dim fld As Folder
Dim tFld As Folder

Set fld = fso.GetFolder("c:\")
If fld.SubFolders.Count > 0 Then
For Each tFld In fld.SubFolders
Debug.Print tFld.path
Next
End If

How do I retreive a specific folder from the collection using a subscript as suggested by the documentation on collections??? nothing seems to work...

fld.SubFolders(1)
fld.SubFolders.item(1)
fld.SubFolders(1).path
etc...

Thanks much,
bill





Dim objFolder As Scripting.Folder
Dim objFile As Scripting.File
Dim objSubdirs As Scripting.Folders
Dim objLoopFolder As Scripting.Folder

Set objFolder = fso.GetFolder(pRs("path"))
For Each objFile In objFolder.Files
Debug.Print objFile.ShortPath
Next objFile
 
After researching the Scripting object model, I learned that the Folders object is apparently not a Collection, but a Scripting.Dictionary. Although they are similar, the Dictionary object apparently can only be accessed by its actual key, not by an index.

You'll have to either know the subfolder name in advance, or use For Each to enumerate the names and then choose one to use as the key. Rick Sprague
 
Folders is apparently not a VB Collection class. There may be one internally but the Folders "collection" does not expose it directly. The doc indicates that ITEM property takes a KEY as opposed to an index. If you get a "not found" exception using Item(1) then I guess Folders can't be "indexed".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top