[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

for eric37 or anyone else...

Posted on 1999-11-12
6
Medium Priority
?
150 Views
Last Modified: 2010-05-18
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

0
Comment
Question by:vbkann
6 Comments
 
LVL 3

Expert Comment

by:manojamin
ID: 2204314
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
 
LVL 1

Author Comment

by:vbkann
ID: 2204386
no this doesnt work...as i get an error file not found on this line:

If (GetAttr(sPath & sName) And FileOrDir) = FileOrDir Then
0
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2204447
When you set sPath, it needs to have a backslash at the end of the string...

For example:

sPath = "C:\WINDOWS\"

Cheers!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 14

Expert Comment

by:mcrider
ID: 2204457
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2204499
Yep...
0
 
LVL 1

Author Comment

by:vbkann
ID: 2204507
thanks
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question