Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OK I am now 3 errors away from completing my goal of getting this program to work but the function I am using goes like this..

VB
Public Iterator Function _matches(ByVal path As String) As IEnumerable(Of FileInfo)
            Dim findData As New Win32.FindData()
            Dim fileName As String

            Using handle As Win32.SafeFindHandle = Win32.SafeNativeMethods.FindFirstFile(path.Combine(path, "*"), findData)
                If Not handle.IsInvalid Then
                    Do
                        fileName = findData.fileName

                        If String.IsNullOrEmpty(fileName) Then
                            Continue Do
                        End If
                        If String.Equals(fileName, ".", StringComparison.Ordinal) Then
                            Continue Do
                        End If
                        If String.Equals(fileName, "..", StringComparison.Ordinal) Then
                            Continue Do
                        End If

                        ' iff directory, dive into it
                        If 0 <> (CInt(FileAttributes.Directory) And findData.fileAttributes) Then
                            If m_includeSubDirs Then
                                For Each fi As FileInfo In _matches(path.Combine(path, fileName))
                                    Yield Async(fi)
                                Next fi
                            End If
                        Else
                            For Each fileSpec As Regex In m_fileSpecs
                                If fileSpec.IsMatch(fileName) Then
                                    Yield New FileInfo(path.Combine(path, fileName))
                                    Exit For
                                End If
                            Next fileSpec
                        End If
                    Loop While Win32.SafeNativeMethods.FindNextFile(handle, findData)
                End If
            End Using
        End Function
    End Class



Microsoft has released the new yield in async iterator but it is for some reason giving me problems in 3 places giving Me problems where ever the instruction " Path.Combine " is used.....

Hear is the exact lines I am trying to fix from this Function:

VB
(1).  Using handle As Win32.SafeFindHandle = Win32.SafeNativeMethods.FindFirstFile(path.Combine(path, "*"), findData)

(2).  For Each fi As FileInfo In _matches(path.Combine(path, fileName))

(3). Yield New FileInfo(path.Combine(path, fileName))

I hope I have given enough Information about my problem as I badly need it to work Thank you all very much in advance :)
Posted
Updated 17-Nov-11 8:37am
v4

1 solution

For the Path error, I think the problem lies in the fact that your function accepts a path parameter, the method is actually needing to using the Path function from the System.IO namespace and is using the wrong one.

Fully qualify the path.combine to System.IO.Path.Combine and that should sort that problem.
 
Share this answer
 
Comments
Dale 2012 20-Nov-11 6:42am    
I have done what you instructed and by changing path.combine to system.io.path.combine it removes the errors and the program loads but once I click search to filter it freezes and does nothing. No exception is thrown will you consider looking at the project in vb.net as i am lost?

thank you in advance for your response :)
DaveAuld 20-Nov-11 8:51am    
Are you sure it is is not just locking the GUI and the search is actually occurring in the background. To prevent lockups of the main UI you should run long task in a backgroundworker thread.
Dale 2012 20-Nov-11 11:09am    
yes I am fairly sure that it is because It works fine in C# but has caused my nothing but grief with vb.net and other than the system.io.path suggestion there may be 2 more instances within my safenativehandling that also have errors.

Public Shared Function FindFirstFile(ByVal fileName As String, <[In](), Out()> ByVal findFileData As FindData) As SafeFindHandle
End Function

<[In](), Out()> says that it is undeclared. Seeing as it does fine in C# I am unsure what it's declaration is.

thank you for reading this.
Dale 2012 20-Nov-11 11:10am    
there is 7 issues most the same but a few that are not if you will be willing to look at it for 5mins or so Id be very appreciative to your efforts.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900