|
-
Jun 9th, 2000, 01:46 AM
#1
Thread Starter
Hyperactive Member
I need to have a user navigate to a directory and then have all the subdirectories in that directory listed in a list box.
I can do the list box part if I provide the directory explicitly, but I want the user to naviagate there and choose it at run time....
Can this be done with a CommonDialog? If so, how? I'm stumped. It won't seem to return anything to me unless I choose a file.
Thanks!!
-
Jun 9th, 2000, 03:38 AM
#2
Fanatic Member
Drop this in your declaration of your form with a listbox
To call it: Call p_Get_SubDirectories(Dir1.Path)
Code:
Option Explicit
Sub p_Get_SubDirectories(strPath As String)
'PURPOSE: If Path lacks a "\", add one to the end
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
'PURPOSE: Find file
Dim strReturn As String
strReturn = Dir(strPath & "*.*", vbDirectory)
Dim strSubDir As String
Do Until strReturn = ""
'PURPOSE: Don't process "." and "..", they aren't real files
If strReturn <> "." And strReturn <> ".." Then
'PURPOSE: Check to see if it is a Directory
If FileLen(strPath & strReturn) = 0 Then 'Directory is consist of 0 byte
If GetAttr(strPath & strReturn) = vbDirectory Then
strSubDir = strSubDir & strPath & strReturn & ";"
End If
End If
End If
strReturn = Dir()
Loop
'---------------------------------------------------------
Dim intPos As Integer
Do Until strSubDir = ""
'PURPOSE: Locate the first ";" position - which represent the first directory
intPos = InStr(1, strSubDir, ";")
'PURPOSE: Strip the first directory name
strReturn = Left$(strSubDir, intPos - 1)
frmMain_Directory.List1.AddItem strReturn
'PURPOSE: Recursive - go into the 1st level of each sub directory
Call p_Get_SubDirectories(strReturn)
'PURPOSE: Strip out the first directory name since
' the file doesn't exsit in that directory
strSubDir = Mid(strSubDir, intPos + 1) 'Strip what you don't need
Loop
End Sub
Chemically Formulated As:
Dr. Nitro
-
Jun 9th, 2000, 03:40 AM
#3
use a directory box in VB.
-
Jun 9th, 2000, 03:53 AM
#4
Thread Starter
Hyperactive Member
The meat of the question is this: Does it have to be a DirListBox?
-
Jun 9th, 2000, 04:05 AM
#5
Fanatic Member
Use my codes with a regular listbox.
Chemically Formulated As:
Dr. Nitro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|