Link to home
Start Free TrialLog in
Avatar of frontback45
frontback45

asked on

Merge Multiple FileInfo Arrays

I am using the DirectoryInfo.GetFiles method to search directories for a certain file type.  The GetFiles method returns a FileInfo file list.  I have several directories that I need to search, so I need to combine several FileInfo arrays that I need to combine.  What is the best way to combine these arrays, or is there a better solution?

Here is the code.  I have a loop where I am passing a path into the function, and it find all of the PDFs in the subdirectories.  I need to combine the FileInfo arrays in the loop.

Private Function FindAllPDFsInArchives(ByVal Archives As DataTable) As FileInfo()
       
        Dim strArchiveFullPath As String

        For i As Integer = 0 To Archives.Rows.Count - 1
            strArchiveFullPath = Archives.Rows(i).Item("PATH").ToString.Trim()
       
            aAllDocsInArchive = SelectAllDocsInArchive(

        Next

        Return allDocsInArchive
    End Function

Public Function SelectAllDocsInArchive(ByVal DirPath as String) As FileInfo()

        Dim archiveFolder As DirectoryInfo
        Dim findFiles As FileInfo() = Nothing

        Dim strFullPathToDoc As String = DirPath

        archiveFolder = New DirectoryInfo(strFullPathToDoc)

        Try
            findFiles = archiveFolder.GetFiles("*.PDF", SearchOption.AllDirectories)
        Catch ex As Exception
            Throw ex
        End Try

        Return findFiles
    End Function

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Why not create a List(Of FileInfo) that you can append to:
Imports System.Collections.Generic
...

Dim wholeList As New List(Of FileInfo)

...

wholeList.AddRange(archiveFolder.GetFiles("*.PDF", SearchOption.AllDirectories))

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of HooKooDooKu
HooKooDooKu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial