DirectoryInfo类 按扩展名,遍历目录中所有文件

  Public Shared Sub findDirectory(ByVal pDirectory As String, ByVal pAryExtension As ArrayList, ByRef pAryFileInfo As ArrayList)        Try

            Dim directory As String = pDirectory  ' 目录

            Dim dir As New DirectoryInfo(directory)

            Dim infos As FileSystemInfo() = dir.GetFileSystemInfos()

            Dim i As FileSystemInfo

            For Each i In infos

                System.Windows.Forms.Application.DoEvents()

                If TypeOf i Is DirectoryInfo Then

                    Dim dInfo As DirectoryInfo = CType(i, DirectoryInfo)

                    findDirectory(dInfo.FullName, pAryExtension, pAryFileInfo)

                ElseIf TypeOf i Is FileInfo Then

                    If pAryExtension.Contains(i.Extension) Then                        pAryFileInfo.Add(i.FullName)                    End If                End If            Next i

        Catch e As Exception

        End Try

    End Sub

你可能感兴趣的:(exception,String,扩展,each)