|
-
May 17th, 2002, 03:27 PM
#1
Thread Starter
Addicted Member
Getting used to IEnumerator's
I'm trying to write a search routine that will search the hard drive for a list of files to see if they exist, I keep getting this error:
An unhandled exception of type 'System.ArgumentException' occurred in search.exe
Additional information: The parameter is incorrect.
it crashes on this line:
oFolder = oFS.GetFolder(oFolders(FolderKey.Current).Path.ToString)
it also crashes on the msgbox line that is commented out, and I just don't see why.
Public Function File_Search_Test( ByVal rs As ADODB.Recordset) As String
Dim oFS As New Scripting.FileSystemObject()
Dim oFolder As Scripting.Folder
Dim oFolders As Scripting.Folders
Dim oDrives As Scripting.Drives
Dim oDrive As Scripting.Drive
Dim iCount As Short
Dim iFolder As Short
Dim oKey As IEnumerator
Dim FolderKey As IEnumerator
oDrives = oFS.Drives
oKey = oDrives.GetEnumerator
Do Until oKey.MoveNext = False
If oDrives(oKey.Current).DriveType.ToString = "Fixed" Then
oFolders = oDrives(oKey.Current).RootFolder.SubFolders
FolderKey = oFolders.GetEnumerator
FolderKey.MoveNext()
'MsgBox(oFolders.Item(FolderKey.Current).Name.ToString)
oFolder = oFS.GetFolder(oFolders(FolderKey.Current).Path.ToString)
MsgBox(oFolder.Name)
End If
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 17th, 2002, 08:56 PM
#2
Addicted Member
I think FolderKey.Current returns an Object. You may have to do something like this.
Ctype(FolderKey.Current, Folder)
That which does not kill us, only makes us stronger. 
-
May 17th, 2002, 10:02 PM
#3
Addicted Member
This will work better than my last suggestion. Is it what you were after?
Public Function File_Search_Test() As String
Dim oFS As New Scripting.FileSystemObject()
Dim oFolder As Scripting.Folder
Dim oFolders As Scripting.Folders
Dim oDrives As Scripting.Drives
Dim oDrive As Scripting.Drive
Dim iCount As Short
Dim iFolder As Short
Dim oKey As IEnumerator
Dim FolderKey As IEnumerator
Dim CurrentFolder As Scripting.Folder
oDrives = oFS.Drives
oKey = oDrives.GetEnumerator
Do Until oKey.MoveNext = False
If oDrives(oKey.Current).DriveType.ToString = "Fixed" Then
oFolders = oDrives(oKey.Current).RootFolder.SubFolders
FolderKey = oFolders.GetEnumerator
FolderKey.MoveNext()
''''''''''''''''''''''''''''''''''''''''''''''''
CurrentFolder = CType(FolderKey.Current, Scripting.Folder)
MsgBox(CurrentFolder.Name)
'''''''''''''''''''''''''''''''''''''''''''''''''
End If
Loop
End Function
That which does not kill us, only makes us stronger. 
-
May 20th, 2002, 10:02 AM
#4
Thread Starter
Addicted Member
Yea I talked to one of my C# friends over the weekend, and the answer we came up with that worked was:
FolderKey = oFolders.GetEnumerator
FolderKey.MoveNext
FolderKey.Current.Name.ToString
Instead of
FolderKey = oFolders.GetEnumerator
FolderKey.MoveNext
oFolders.Item(FolderKey.Current).Name.ToString
That seems weird to me, becase this line works:
oFolders = oDrives(oKey.Current).RootFolder.SubFolders
From what I've learned either this should work:
oFolders = oDrives(oKey.Current).RootFolder.SubFolders
oFolders.Item(FolderKey.Current).Name.ToString
Or I should have to do use:
FolderKey.Current.Name.ToString
oFolders = oKey.Current.RootFolder.SubFolders
it just doesn't seem right that oFolders = oDrives(oKey.Current).RootFolder.SubFolders works while the other doesn't could this be a bug in VB.NET ?
cType, I take it that is for casting? my C# friend kept asking me if I knew how to cast..
-Daryl
"Two More Rolls of Duct tape, and the world is mine!"
VB.NET Guru
-
May 20th, 2002, 10:15 AM
#5
yeah CType is the closest equivalnt to C# casting..
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
|