How to Get SubFolder of a Particular Folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mafaisal
    New Member
    • Sep 2007
    • 142

    How to Get SubFolder of a Particular Folder

    Hello,

    I am Using VB6

    Here Hw to Get SubFolder Names of Given Folder

    I have here Code But Error is coming

    Code:
    Dim FSO As New FileSystemObject
    Dim FOL As Folder
    Dim Path As String
    Path = InputBox("Enter Path")
    Set FOL = FSO.GetFolder(Path)
    Dim i As Integer
    For i = 1 To FOL.SubFolders.Count
     MsgBox FOL.SubFolders.Item(i).Name
    Next
    Here Error is coming, Plz Give me reply

    Faisal
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Originally posted by mafaisal
    Hello,

    I am Using VB6

    Here Hw to Get SubFolder Names of Given Folder

    I have here Code But Error is coming

    Code:
    Dim FSO As New FileSystemObject
    Dim FOL As Folder
    Dim Path As String
    Path = InputBox("Enter Path")
    Set FOL = FSO.GetFolder(Path)
    Dim i As Integer
    For i = 1 To FOL.SubFolders.Count
     MsgBox FOL.SubFolders.Item(i).Name
    Next
    Here Error is coming, Plz Give me reply

    Faisal

    Not sure what the error is but I would change it to use FOR..EACH loop as the following example illustrates:

    Code:
    Sub ShowFolderList(folderspec)
        Dim fs, f, f1, fc, s
        Set fs = New FileSystemObject
        Set f = fs.GetFolder(folderspec)
        Set fc = f.SubFolders
        For Each f1 in fc
            s = s & f1.name 
            s = s &  vbCrLf
        Next
        MsgBox s
    End Sub

    Comment

    Working...