PDA

Click to See Complete Forum and Search --> : Directories


markwestcott
Jan 13th, 2000, 01:46 AM
Hi everyone. I wonder if i can have some help?:

I want my program to do the following:

1) Ask the user to specify a directory
2) List all the directorys within this directory which match a certain criteria (e.g. number of files < 5) to a combo box.

Any ideas?

Aaron Young
Jan 13th, 2000, 02:10 AM
Something like:

Private Sub Command1_Click()
Dim sSubs() As String
Dim lSubs As Long
Dim sDir As String
Dim lFiles As Long

Combo1.Clear
If Right(txtDir, 1) <> "\" Then txtDir = txtDir & "\"
sDir = Dir(txtDir & "*", vbDirectory)
While Len(sDir)
If Left$(sDir, 1) <> "." Then
If (GetAttr(txtDir & sDir) And vbDirectory) = vbDirectory Then
ReDim Preserve sSubs(lSubs)
sSubs(lSubs) = sDir
lSubs = lSubs + 1
End If
End If
sDir = Dir
Wend

If lSubs = 0 Then Exit Sub

For lSubs = 0 To lSubs - 1
sDir = Dir(txtDir & sSubs(lSubs) & "\*.*", vbHidden + vbNormal + vbSystem)
lFiles = 0
While Len(sDir)
If Left(sDir, 1) <> "." Then lFiles = lFiles + 1
sDir = Dir
Wend
If lFiles < Val(txtFiles) Then Combo1.AddItem txtDir & sSubs(lSubs)
Next
End Sub

This will only list Directories immeadiately in the specified Directory, if you want it to go down further you'll have to use Recursion.

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

markwestcott
Jan 13th, 2000, 03:32 AM
Thanks a lot. I haven't tried the code yet, but knowing your record, I'm sure it will work perfectly! I'll post with the results.

markwestcott
Jan 13th, 2000, 03:43 AM
Great! It works, thank you so much. I really appreciate the help that you have given me and everybody else on this forum.

Thanks again


Mark