Results 1 to 4 of 4

Thread: Directories

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    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?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Something like:
    Code:
    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
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Posts
    79

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width