Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have the following function that does a recursive search and adds all files to a list box. But when I hit a file that has no extension I get an error. I can't add the extension as its on a DVD. Does anyone know how I can solve this

Here is the function

VB
Private Function RecursiveSearch(ByVal path As String) As Boolean
        Dim dirInfo As New IO.DirectoryInfo(path)
        Dim fileObject As FileSystemInfo
        For Each fileObject In dirInfo.GetFileSystemInfos()
            If (fileObject.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then
                RecursiveSearch(fileObject.FullName)
            Else
                Me.lstDirectory.Items.Add(fileObject.FullName)
            End If
        Next
        Return True
    End Function
Posted
Comments
Bernhard Hiller 27-May-13 4:17am    
"I get an error" - tell us the error message!

1 solution

Why not just use the non-recursive function Directory.GetFiles[^]

VB
Dim files As String() = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)
You can then add them all to your list with AddRange, if you need to.
 
Share this answer
 
Comments
johnjsm 27-May-13 4:48am    
Thanks a million. Don't know why I always thought that function would not do sub directories.
OriginalGriff 27-May-13 5:14am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900