Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing Sub Directories 2

Status
Not open for further replies.
Jul 5, 2001
40
US
I used to use VB about 5 years ago on a constant basis and I am trying to get back into it again so bare with me here.

I am trying to write an update program that will have sub directories that will vary. I don't want to place them in the registry or an .ini file since that seems like to much work for such a small amount of information neccessary.

The directory layout will be something like this:

<Main Dir>
|
|-<SubDir1>
|
|-<SubDir2>

I was wondering if there were some way to have it scan for the sub directories and then pass them to either a list box or an array so that I can use that information for additional coding.

I appreciate any help in advance.
 
lstPaths.AddItem gstrSourceRoot

' Get complete list of source paths and put into lstPaths.
GetDirs gstrSourceRoot

Private Sub GetDirs(ByVal strPath As String)
Dim intSubDir As Integer
Dim intX As Integer
Dim strSubDirs() As String
Dim strTemp As String
On Error GoTo ErrorHandler

' Look for subdirectories
ReDim strSubDirs(5)
strTemp = Dir(strPath & &quot;*.*&quot;, vbDirectory)
Do While Len(strTemp) > 0
If Left(strTemp, 1) <> &quot;.&quot; Then
If IsDirectory(strPath & strTemp) Then
strSubDirs(intSubDir) = strPath & strTemp & &quot;\&quot;
intSubDir = intSubDir + 1
lstPaths.AddItem strPath & strTemp & &quot;\&quot;
lstPaths.Refresh
If intSubDir = UBound(strSubDirs) Then
ReDim Preserve strSubDirs(intSubDir + 5)
End If
End If
End If
strTemp = Dir
DoEvents
If gblnCancel Then Exit Sub
gdtCurrentTime = Time
sbrMain.Panels(4).Text = &quot;Elapsed Time : &quot; & Format(gdtCurrentTime - gdtBeginTime, &quot;hh:mm:ss&quot;)
sbrMain.Refresh
Loop

For intX = 0 To intSubDir - 1
GetDirs (strSubDirs(intX))
Next intX

'txtCount.Text = lstPaths.ListCount
sbrMain.Panels(2).Text = &quot;Folder Count : &quot; & lstPaths.ListCount
sbrMain.Refresh
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub

 
Tried this but IsDirectory(strPath & strTemp) claims to be invalid. Did you program this function some place else?
 
Yup. Sorry about that.

Public Function IsDirectory(ByVal strFile As String) As Boolean
Dim intAttr As Integer
Dim intErr As Integer

On Error Resume Next
intAttr = GetAttr(strFile)
intErr = Err.Number
On Error GoTo 0
IsDirectory = (intErr = 0) And ((intAttr And vbDirectory) = vbDirectory)

End Function
 
Alright, cool. Now were getting somewhere. Here's the problem I'm having though. After placing in your code it only allows me to see the C:\Program Files\Microsoft Visual Studio\VB98 directory. So it returns all the directories and sub directories within there. I've tried to manipulate the code to get it to point to the most current folder but I don't think I'm getting it because either the program freezes or the list box returns nothing.

Can you please help one me one more time.

Thanks Again
 
Sorry, a bit more info...

Where does the gstrSourceRoot come in?

It's blank so I am assuming that it is reading the current root.
 
If you use this:

gstrSourceRoot = &quot;C:\&quot;

it will return all folders on the C partition.

 
That's perfect. I got it work 100%. Now off to my other programming woes.

Thanks
 
BobWman..

thanks for the code.. this will help alot in a project im working on.. i gave ya a star live it up heheh :) take care and thanks again! in the begining man created code.
in the end code will create man.
clones are coming only matter of time.
examples?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top