1 2 Private Sub WalkAllFiles(ByVal strPath As String, Optional ByVal IgnoreDupes As Boolean = False, Optional ByVal bOnlyPDFs As Boolean = True) 3 Dim arDirs() As DirectoryInfo 4 Dim oDir As New DirectoryInfo(strPath) 5 Dim arFiles(), oFile As FileInfo 6 7 'Get a list of files for the current directory' 8 9 Try 10 If bOnlyPDFs Then 11 arFiles = oDir.GetFiles("*.pdf") 12 Else 13 arFiles = oDir.GetFiles("*.*") 14 End If 15 For Each oFile In arFiles 16 sbpMain.Text = "Adding " + oFile.FullName 17 Try 18 m_colWalkFiles.Add(oFile.FullName) 19 Catch ex As System.Exception 20 If Not IgnoreDupes Then Throw New ArgumentException("Duplicate File.") 21 End Try 22 Next 23 Catch 24 //Discard the error 25 End Try 26 /*Process all files in subdirectories (recurse)*/ 27 arDirs = oDir.GetDirectories() 28 For Each oDir In arDirs 29 WalkAllFiles(oDir.FullName, IgnoreDupes, bOnlyPDFs) 30 Next 31 End Sub
You need to create an account or log in to post comments to this site.