Hi, take a look to my coding:

Dim Dir As New DirectoryInfo("C:\Users\Leo\Desktop\Data Lau")
            Dim svrDir As New DirectoryInfo(" C:\Users\Leo\Desktop\Server")

            Dim FileList As FileInfo() = Dir.GetFiles("*.*", SearchOption.TopDirectoryOnly)
            Dim svrFileList As FileInfo() = Dir.GetFiles("*.*", SearchOption.TopDirectoryOnly)
            Dim fi As IO.FileInfo            
            Dim svrfi As IO.FileInfo
            Dim isSame As Boolean = False
            Dim storfilelist As FileInfo() = Nothing

            For Each fi In FileList
                For Each svrfi In svrFileList
                    If fi.Name.Equals(svrfi.Name) Then
                     'how to write the codes here?

                    Else
                        Continue For
                    End If
                Next
            Next

I wants to compare two file lists and get all the files which are same name in the two folders. Then I wants to store the selected file object into "storfilelist". How to write the coding insides the for each loop?

Recommended Answers

All 3 Replies

What about reading the file list from 1st directory and storing somewhere (may be in an array), and later read from second directory and check the same in the array. If it exists store in another array and proceed.

What about reading the file list from 1st directory and storing somewhere (may be in an array), and later read from second directory and check the same in the array. If it exists store in another array and proceed.

Means I needs to create an object array like " Dim array As Object" and proceed it? But if do this way, while I store in another array, how can I get the file info of the items, or access the second array as a fileinfo object?

I had tried this way:

Dim array As Object
            Dim array1 As New Object

            array = FileList.Clone
            Dim i As Integer = 0
            For Each a As Object In array
                For Each svrfi In svrFileList
                    If a.Equals(svrfi.Name) Then
                        array1(i) = a
                    Else
                        Continue For
                    End If
                Next
            Next

            storfilelist = array1

            For Each varlist As IO.FileInfo In storfilelist
                Console.WriteLine(varlist.Name)
            Next

But it got error of "unable to cast object of type'System.Object' to 'System.IO.FileInfo[]'". How to make the type same? or got any methods?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.