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

Get Sub Folder Names

Status
Not open for further replies.

ProjectExplorer

Programmer
Mar 22, 2002
95
GB
I need to get the names of all subfolder names in a main folder. I have set reference to run time scripting and using the FileScripting object but cannot work out the code. I believe its along the lines of:

Public Function Get SubFileName()

Dim MainFolder As Folders
Dim F As Folder
Dim Fsys As New Scripting.FileSystemObject

Set MainFolder = Fsys.GetFolder("C:\Temp\")

For Each F In MainFolder
Debug.Print F.Name
Next F

End Function

....but doesn't work. Any ideas please.

 
try something like this:
Code:
Public Function GetSubFileName()

    Set Fsys = [red]CreateObject("Scripting.FileSystemObject")[/red]

    Set MainFolder = Fsys.GetFolder("C:\Temp\")

    For Each F In MainFolder.[red]subfolders[/red]
        Debug.Print F.Name
    Next F

End Function

_________________
Bob Rashkin
 
Thanks for your suggestion - but couldnt get this to work. Will keep trying though.
 
Cracked it! The code is:

Public Function GetSubFolderNames()

Dim MainFolder As Scripting.Folder
Dim F As Scripting.Folder
Dim FI As Scripting.File

Dim Fsys As New Scripting.FileSystemObject
Set MainFolder = Fsys.GetFolder("C:\Temp")

For Each F In MainFolder.SubFolders
Debug.Print F.Name
Next F

End Function

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top