“get all files in all subdirectories c#” Code Answer’s

Posted on

In this article we will learn about some of the frequently asked C# programming questions in technical like “get all files in all subdirectories c#” Code Answer’s. This article will show you simple practices on dealing with performance problems, starting with when you need to deal with them at all. You will see techniques to detect if a problem exists, find the specific cause, and fix it. Below are some solution about “get all files in all subdirectories c#” Code Answer’s.

get all files in all subdirectories c#

how to get all files from folder and subfolders in c#
1 private IEnumerable GetAllFiles(string path, string searchPattern) 2 { 3 return Directory.EnumerateFiles(path, searchPattern).Union( 4 Directory.EnumerateDirectories(path).SelectMany(d => 5 { 6 try 7 { 8 return GetAllFiles(d, searchPattern); 9 } 10 catch (Exception) 11 { 12 return Enumerable.Empty(); 13 } 14 })); 15 } 16 ​ 17 //or special for c# and .cs files 18 /*private List GetAllCsFilesFromDirectory(string directory, string searchPattern) 19 { 20 List lstFilesFound = new List(); 21 try 22 { 23 foreach (string path in Directory.GetDirectories(directory)) 24 { 25 foreach (string item in Directory.GetFiles(path, CsharpFileExtension, SearchOption.AllDirectories)) 26 { 27 lstFilesFound.Add(item); 28 } 29 ​ 30 GetAllCsFilesFromDirectory(path, searchPattern); 31 } 32 } 33 catch (Exception e) 34 { 35 Console.WriteLine(e); 36 } 37 ​ 38 return lstFilesFound; 39 }*/

Leave a Reply

Your email address will not be published.