By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,571 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,571 IT Pros & Developers. It's quick & easy.

Spider Function Update

P: n/a
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

Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"pmclinn" <pm*****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
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

Nov 21 '05 #2

P: n/a
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:
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


Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.