Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

asked on

Loop thru a directory put filenames in a combobox vb6

I have a program where a homeowner can get-track bids on different home repair-improvements
The homowner can type a new project name  into a combo box(cboBids) and new Directory is created
I want to put all the directory names in a combobox on form load
The homeowners directory is created when entered into textboxes
Typical Paths
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Painting Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Roofing Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\Bathroom Remodle Bids
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd\New Fence Bids
The last part
Example:
With Me.cboBids
.AddItem "paintingBids"
.AddItem "Roofing Bids"
.AddItem "Bathroom Remodle Bids"
.AddItem "New Fence Bids"
End With
How can this be done ?
Avatar of ste5an
ste5an
Flag of Germany image

Use either the Dir() function or the FileSystemObject.

' Add a reference to the Microsoft Scripting Runtime.
Dim fso As New FileSystemObject
Dim f As Folder
  
For Each f  In fso.GetFolder("<yourFolderPath>").SubFolders
  Debug.Print f.Name
Next f
Set fso = Nothing

Open in new window

Avatar of isnoend2001

ASKER

Thanks ste5an
Is there a way without using fso ?

mstrOwnerFolder holds this:
C:\Documents and Settings\All Users.WINDOWS\Documents\RoofCalculator\Williams 1247 RiverBend rd
tried this to no avail:

Sub AddFoldersToCbo()
Dim MyFile, MyPath, MyName
MyPath = mstrOwnerFolder  ' Set the path.
MyName = Dir(MyPath, vbDirectory)   ' Retrieve the first entry.
Do While MyName <> ""
      If MyPath = vbDirectory Then
        Debug.Print MyName
   End If
   MyName = Dir
Loop
End Sub

Open in new window

Try this:

Note the additions: the GetAttr() function and the last backslash in root path.

   Dim MyFile, MyPath, MyName
   MyPath = "c:\temp\"                 'Set the path (must append the last backslash "\")
   MyName = Dir(MyPath, vbDirectory)   'Retrieve the first entry.
   Do While MyName <> ""
      If (GetAttr(MyPath & MyName) And vbDirectory) Then
         If (MyName <> ".") And (MyName <> "..") Then
            Debug.Print MyName
         End If
      End If
      MyName = Dir()
   Loop

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkaios
jkaios
Flag of Marshall Islands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks jkaios
My pleasure, so glad it works!