We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Merge Multiple FileInfo Arrays

Medium Priority
1,143 Views
Last Modified: 2013-11-26
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

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
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

CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.