Spider Function Update

P

pmclinn

Herfried K. Wagner wrote this function but it only walks one level of
subfolders. How do you update this function so that if it finds all
sub directory files and returns the result like this:

Example of what I need:
Folder A
File 1
File 2
Folder SubA
File 1
File 2

Return to look like this:

File1
File2
SubA\File1
SubA\File2




Herfried Code:

Private Function GetFilesAsFileInfo( _
ByVal strPath As String, _
ByRef astrPatterns As String() _
) As ArrayList
Dim di As DirectoryInfo = New DirectoryInfo(strPath)
Dim al As New ArrayList()
Dim s As String
Dim afi As FileInfo()
Dim fi As FileInfo
For Each s In astrPatterns
afi = di.GetFiles(s)
For Each fi In afi
al.Add(fi)
Next fi
Next s
Return al
End Function
End Module
 
R

rawCoder

Is this what you want ... pass path without ending back slash

Private Sub GetFilesAsFileInfo(ByVal strPath As String, ByRef astrPatterns
As String(), ByRef al As ArrayList)

Dim di As DirectoryInfo = New DirectoryInfo(strPath)

'Dim al As New ArrayList

Dim afi As FileInfo()

For Each s As String In astrPatterns

afi = di.GetFiles(s)

For Each fi As FileInfo In afi

al.Add(fi)

Trace.WriteLine(fi.FullName)

Next fi

Next s

For Each di2 As DirectoryInfo In di.GetDirectories

GetFilesAsFileInfo(strPath & "\" & di2.Name, astrPatterns, al)

Next

End Sub

HTH

rawCoder
 
P

pmclinn

So I finally got this working (This is the general idea and I'm open to
suggestions to improve this code:
Private Sub GetFilesAsFileInfo(ByVal strPath As String)
Dim al As New ArrayList
'al.Add(strPath)
Dim di As DirectoryInfo = New DirectoryInfo(strPath)
For Each diLooper As DirectoryInfo In di.GetDirectories
al.Add(diLooper.FullName)
Console.Out.WriteLine(diLooper.Name)
GetFilesAsFileInfo(diLooper.FullName)
Next
End Sub

Then I pass the directories into Herfried code:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top