for eric37 or anyone else...

Hi....

you know that question where i asked how to get a directory listing.

Well can you please tell me how to modify it so that i can list other directories and not just the main directory.

Here is the code:

Option Explicit

Private Function GetDirs(sPath As String, FileOrDir As Integer) As String
    Dim sName As String
    Dim temp As String
    Dim i As Integer
    Dim sFullList() As String
    ReDim sFullList(0)
    sPath = "c:\" 'Set the path.
    sName = Dir(sPath, FileOrDir) ' Get first directory
    Do While sName <> vbNullString  ' Start looping
        ' Ignore the current directory and the encompassing directory.
    If sName <> "." And sName <> ".." Then
        If FileOrDir = vbDirectory Then
            If (GetAttr(sPath & sName) And FileOrDir) = FileOrDir Then
                sFullList(i) = sName
                ReDim Preserve sFullList(UBound(sFullList) + 1)
                i = i + 1
            End If
        Else
        sFullList(i) = sName
        ReDim Preserve sFullList(UBound(sFullList) + 1)
        i = i + 1
    End If
End If


        sName = Dir 'Get next
    Loop
    QuickSort sFullList, 0, UBound(sFullList)
    For i = 0 To UBound(sFullList)
        If Not sFullList(i) = vbNullString Then
            temp = temp & sFullList(i)
            If i < UBound(sFullList) Then
                temp = temp & ","
            End If
        End If
    Next
    GetDirs = temp
End Function

Private Sub Command1_Click()
    Text1.Text = GetDirs("c:\", vbDirectory) 'list direcories
    Text2.Text = GetDirs("c:\", vbNormal + vbSystem + vbHidden) 'list files
End Sub


' ============================ QuickSort ============================
' QuickSort works by picking a random "pivot" element in SortArray,
' then moving every element that is bigger to one side of the pivot,
' & every element that is smaller to the other side. QuickSort is
' then called recursively with the two subdivisions created by the
' pivot. Once the number of elements in a subdivision reaches two,
' the recursive calls end and the array is sorted.
' ===================================================================
'
Private Sub QuickSort(SortArray() As String, ByVal Low As Long, _
                   ByVal High As Long)
   Dim i As Long, J As Long, RandIndex As Long, Partition As String
   If Low < High Then
      ' Only two elements in this subdivision; swap them if they are
      ' out of order, then end recursive calls:
      If High - Low = 1 Then
         If UCase(SortArray(Low)) > UCase(SortArray(High)) Then
            SWAP SortArray(Low), SortArray(High)
         End If
      Else
         ' Pick a pivot element at random, then move it to the end:
         RandIndex = Rnd() * (High - Low) + Low ' RandInt%(Low, High)
         SWAP SortArray(High), SortArray(RandIndex)
         Partition = UCase(SortArray(High))
         Do
            ' Move in from both sides towards the pivot element:
            i = Low: J = High
            Do While (i < J) And (UCase(SortArray(i)) <= Partition)
               i = i + 1
            Loop
            Do While (J > i) And (UCase(SortArray(J)) >= Partition)
               J = J - 1
            Loop

            ' If we haven't reached the pivot element it means that 2
            ' elements on either side are out of order, so swap them:
            If i < J Then
               SWAP SortArray(i), SortArray(J)
            End If
         Loop While i < J

         ' Move the pivot element to its proper place in the array:
         SWAP SortArray(i), SortArray(High)

         ' Recursively call the QuickSort procedure (pass the
         ' smaller subdivision first to use less stack space):
         If (i - Low) < (High - i) Then
            QuickSort SortArray, Low, i - 1
            QuickSort SortArray, i + 1, High
         Else
            QuickSort SortArray, i + 1, High
            QuickSort SortArray, Low, i - 1
         End If
      End If
   End If
End Sub

Private Sub SWAP(first As String, second As String)
   Dim temp As String
   temp = first
   first = second
   second = temp
End Sub

LVL 1
vbkannAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

manojaminCommented:
Just commnet out this line in 'GetDirs(sPath As String...)' function

sPath = "c:\" 'Set the path.

and provide sPath with the full path, for example. d:\temp or c:\mydir or \\mynetname\shareddir\testundershareddir

Hope this will help you...

0
vbkannAuthor Commented:
no this doesnt work...as i get an error file not found on this line:

If (GetAttr(sPath & sName) And FileOrDir) = FileOrDir Then
0
mcriderCommented:
When you set sPath, it needs to have a backslash at the end of the string...

For example:

sPath = "C:\WINDOWS\"

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mcriderCommented:
OR...

Comment out this line in GetDirs:

    sPath = "c:\" 'Set the path.
   
And then call GetDirs from the command click event this way:


Private Sub Command1_Click()
    Text1.Text = GetDirs("c:\WINDOWS\", vbDirectory) 'list direcories
    Text2.Text = GetDirs("c:\WINDOWS\", vbNormal + vbSystem + vbHidden) 'list files
End Sub

Cheers!
0
Erick37Commented:
Yep...
0
vbkannAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.