vb.net .net 2.0 to .net 1.0...GetFiles

lidds

Well-known member
Joined
Oct 19, 2004
Messages
122
Programming Experience
Beginner
Bit of a strange question, I have done a small app in vb.net using .net 2.0 framework, however the machines in my company only has .net 1.1 installed, my boss does not want to install .net 2.0 on the machines so I am having to convert the app to .net 1.1. The problem is I am stuck on converting this line of code into .net 1.1, can anyone help??

VB.NET:
For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\", FileIO.SearchOption.SearchAllSubDirectories, "*.lic")

thanks

Simon
 
Firstly, that original code would fail because it would throw an exception when it encountered the inaccessible SystemVolumnInformation folder. Even in .NET 2.0 you cannot search an entire root drive for that reason, so you'd have to write your own recursive method. The same is true in .NET 1.x:
VB.NET:
Private Function GetFiles(ByVal folder As String, _
                          ByVal recursive As Boolean, _
                          ByVal filter As String) As String()
    Dim files As New ArrayList

    Try
        files.AddRange(IO.Directory.GetFiles(folder, filter))

        If recursive Then
            For Each subfolder As String In IO.Directory.GetDirectories(folder)
                files.AddRange(Me.GetFiles(subfolder, _
                                           recursive, _
                                           filter))
            Next subfolder
        End If
    Catch
        'This folder is inaccessible so ignore it and continue.
    End Try

    Return DirectCast(files.ToArray(), String())
End Function
 
Back
Top