Dan

Dan

  • NA
  • 23
  • 8.2k

Adding string elements to List

Jun 29 2013 5:19 AM
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)