In general, it is necessary to bypass the directories in the specified folder and return the list of paths to each directory.

How can this be done most quickly? Is there any point in parallelism?

  • Maybe this will help you msdn.microsoft.com/ru-ru/library/dd997370 ( v=vs.110).aspx - Vanya Avchyan
  • @VanyaAvchyan, issue as an answer. - Alexis
  • 2
    it makes no sense to parallelize; all the same, everything will rest on the performance of disk access, especially if the operation is a one-time operation. - rdorn

2 answers 2

Maybe this will help you.

A practical guide. Listing directories and files https://msdn.microsoft.com/ru-ru/library/dd997370(v=vs.110).aspx

Listing file names in a directory and subdirectories

Example:

using System; using System.IO; using System.Linq; class Program { static void Main(string[] args) { try { var files = from file in Directory.EnumerateFiles(@"c:\", "*.txt", SearchOption.AllDirectories) from line in File.ReadLines(file) where line.Contains("Microsoft") select new { File = file, Line = line }; foreach (var f in files) { Console.WriteLine("{0}\t{1}", f.File, f.Line); } Console.WriteLine("{0} files found.", files.Count().ToString()); } catch (UnauthorizedAccessException UAEx) { Console.WriteLine(UAEx.Message); } catch (PathTooLongException PathEx) { Console.WriteLine(PathEx.Message); } } } 
  • This is the answer link. It would be much more valuable if you posted in the response code and / or a brief squeeze of the ideas presented in the article. - VladD pm
  • @VladD I will not say more on this page through links, let people come in and see if they can find solutions to other problems - Vanya Avchyan
  • @VanyaAvchyan a short example with respect to the question still does not hurt, for the completeness of the answer. - rdorn 6:49 pm
  • @rdorn Thank you, I'll keep it in mind - Vanya Avchyan
  • @ VanyaAvchyan, Parallelism makes sense to use? Is not it better to bypass the hands? If EnumerateFiles falls with an error, I won’t get any collection elements at all ... - iluxa1810

Assuming there is a user interface that shows the top level of the directory tree.

You can use different threads for the user interface and the actual filling of the tree.

It also makes sense to first get a list of subdirectories in the current directory and immediately issue it to the UI - the user will quickly see the response. After that, already run on the subdirectories - the UI will not change from this or it will hardly change.