|
-
May 4th, 2000, 03:54 PM
#1
Thread Starter
Junior Member
well, found out the main problem in my program, lies within this code.
counter = 0
hFile = FindFirstFile(strCurrentDir, WFD)
If hFile = -1 Then
hFile FindClose(hFile)
Exit Sub
End If
Do
If (WFD.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
sTmp = TrimNull(WFD.cFileName)
If sTmp <> "." And sTmp <> ".." Then
counter = counter + 1
strFolderName(counter) = sTmp
blnResults = True
End If
End If
Loop While FindNextFile(hFile, WFD) 'this is the line it bombs out in
'close the find handle
hFile = FindClose(hFile)
better explain.
I want to list in the array STRFOLDERNAME, all sub-folders within a predetermined Results folder. This works ok, however, if any other files are present within this directory (apart from a txt file) the system total crashes out and throws up a lot of errors through Dr. Watson.
Can anyone please tell me what I am doing wrong here.
Please, why is this not working
many thanks
-
May 4th, 2000, 05:03 PM
#2
Fanatic Member
Sub - Directories
This algorithim will get you every sub - directory in a particular directory. In this example it will hold an array of all the sub directories in "c:\program files".
Code:
Option Explicit
Dim fs, folder1
Dim iCount As Long
Dim folderNames() As String
Private Sub Command1_Click()
Dim i As Long
'create a file scripting object
Set fs = CreateObject("Scripting.FileSystemObject")
'size the array to 100
ReDim Preserve folderNames(1 To 100) As String
iCount = 1
getFolderNames (fs.GetFolder("c:\program files"))
'redim the array to the number of folders collected
ReDim Preserve folderNames(1 To (iCount - 1)) As String
'loop to show all the names
For i = 1 To UBound(folderNames)
MsgBox folderNames(i)
Next i
End Sub
Private Sub getFolderNames(folderCol)
For Each folder1 In folderCol.SubFolders
If iCount = UBound(folderNames) Then
ReDim Preserve folderNames(1 To UBound(folderNames) + 50) As String
End If
folderNames(iCount) = folder1.Name
iCount = iCount + 1
getFolderNames (fs.GetFolder(folder1))
Next
End Sub
Hope this helps.
[Edited by Iain17 on 05-05-2000 at 11:58 AM]
[Edited by Iain17 on 05-05-2000 at 02:31 PM]
Iain, thats with an i by the way!
-
May 4th, 2000, 05:28 PM
#3
Thread Starter
Junior Member
nice one
cheers big ears!
thank you, does what i wnat to a tee.
-
May 4th, 2000, 06:02 PM
#4
Fanatic Member
Thats the way it goes Big Nose! 
Made an ammendment to it though. You now pass the folder to the sub.
Iain, thats with an i by the way!
-
May 4th, 2000, 11:32 PM
#5
Fanatic Member
Just to clarify
Just to clarify a point that might have been a bit unclear. The solution i posted earlier in this thread returns EVERY sub-directory in a directory.
This includes the sub-directories of the sub-subdirectories, and so on.
[Edited by Iain17 on 05-05-2000 at 05:35 PM]
Iain, thats with an i by the way!
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
|