1
Answer

Adding string elements to List

Dan

Dan

11y
1k
1
Hello guys. I have an recursion function which opens me all directories from the path parameter, and gets all .pdf files. Instead of printing each file to the Console, I want to add it to a List<string> which is one of the function parameters.

This is my code:
        private static void GetAllFilesFrom(string path, string extension)
        {
            try
            {
                if ((File.GetAttributes(path) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
                {
                    foreach (string folder in Directory.GetDirectories(path))
                    {
                        foreach (string file in Directory.GetFiles(folder, extension))
                        {
                            Console.WriteLine(file);
                        }
                        GetAllFilesFrom(folder, extension);
                    }
                }
            }
            catch (UnauthorizedAccessException) { }
        }

Answers (1)
Next Recommended Forum