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?
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.
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); } } } 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.
Source: https://ru.stackoverflow.com/questions/541428/
All Articles