Question Recursive File Search

RyanB88

New member
Joined
Mar 21, 2005
Messages
3
Programming Experience
1-3
I have a series of text files in multipule diffrent sub directories. I found the following functions on the Internet:

VB.NET:
Private Overloads Function Recursive(ByVal strPath As String)
        Dim oDir As New System.IO.DirectoryInfo(strPath)
        Dim oSubDir() As System.IO.DirectoryInfo
        Dim oFiles() As System.IO.FileInfo
        Dim i As Int32

        oFiles = oDir.GetFiles
        For i = 0 To oFiles.Length - 1
            Debug.WriteLine(oFiles(i).Name.ToString)
        Next


        oSubDir = oDir.GetDirectories()
        For i = 0 To oSubDir.Length - 1
            Debug.WriteLine(oSubDir(i).Name.ToString)
            'more code to do whatever here

            Call Recursive(oSubDir(i), 1)
        Next

        

    End Function

    Private Overloads Function Recursive(ByVal oDir As System.IO.DirectoryInfo, ByVal intLevel As Int32)
        Dim oSubDir() As System.IO.DirectoryInfo
        Dim oFiles() As System.IO.FileInfo
        Dim i As Int32

        oFiles = oDir.GetFiles
        For i = 0 To oFiles.Length - 1
            Debug.WriteLine(New String(" ", intLevel) & ">" & oFiles(i).Name.ToString)
        Next

        oSubDir = oDir.GetDirectories()
        For i = 0 To oSubDir.Length - 1
            Debug.WriteLine(New String(" ", intLevel) & oSubDir(i).Name.ToString)
            'more code to do whatever here

            Call Recursive(oSubDir(i), intLevel + 1)
        Next

        
    End Function

The functions will make a direcotry tree in my debug window, that looks something like this:

wp-signup.php
wp-trackback.php
xmlrpc.php
wp-admin
>admin-ajax.php
>admin-footer.php
>admin-functions.php
wp-content
>index.php
plugins
>hello.php
>index.php

What I want it to do is to have it return an array of relitive file paths, from the starting direcotry I give the function. Then I will use a loop to cycle though each file in the array to make certain changes.

Something like this:

wp-signup.php
wp-trackback.php
xmlrpc.php
wp-admin/admin-ajax.php
wp-admin/admin-footer.php
wp-admin/admin-functions.php
wp-content/index.php
wp-content/plugins/hello.php
wp-content/plugins/index.php

Any ideas on how to acomplish this?
 
Back
Top