SoFunction
Updated on 2025-03-07

Export all files in the folder to log files c# recursive algorithm learning example

Algorithm articles always bring us endless thoughts and interests. One problem and multiple solutions depends on how you think about it. Regarding the problems raised by the title, I think using recursion is a relatively effective method. Of course, there are many use occasions for recursion, such as the operation of tree classification lists, etc.

Notice:

When using recursion, beginners should pay special attention to "exit". They must provide an exit for recursion, otherwise your memory will overflow. Haha, everyone must have seen memory overflow, and they all came from that time, haha.

Recursion in the code:

Copy the codeThe code is as follows:

static void GetFiles(List<string> arr, string dir)
        {

            ((dir));
            var subDir = (dir).ToList();
            if (subDir != null && > 0)
                (j =>
                {
                    GetFiles(arr, j);
                });

        }

Program entry

Copy the codeThe code is as follows:

static void Main(string[] args)
        {
string path = "F:\\softmare\\Fiddler2 Chinese";
            var obj = FileSync(path);

            using ( srFile = new (path + "\\"))
            {
                (i =>
                {
                    (i);
                });

            }

("Filling is completed");

            ();
        }