0

I'm using Directory.GetDirectories(path, "*", SearchOption.AllDirectories) to get all of the paths, but for directories containing larger amounts of subfolders it can take quite a while for it to complete (upwards of 5 minutes or so with 50k folders).

I'm using Unity and am stuck with .NET 2.0, so I can't use Directory.EnumerateDirectories() which I've heard is faster. The only way I can think of to make it faster is to run similar code on a separate thread and just iterate through the available paths, but I'm wondering if there's either a better way or one that's just plain faster.

Ryan Foster
  • 51
  • 1
  • 2
  • can you split your files in different base folders? I mean to have folder for images, one for docs and one for videos for example (in the base level) – Muhammad Soliman Dec 21 '17 at 02:48
  • Can the results be processed "interactively"? ie. is only needing to show a subset of expand a given folder.. using the GetDirectories(root) - walking as needed; this form is also "parallelizable" - or otherwise paginating/filtering might be useful. This can also avoid building the "entire array of directories" if consumed in a more incremental/streaming fashion. – user2864740 Dec 21 '17 at 02:50
  • even your call to the same code multiple times in the different threads will not help you as you're calling the same code and each one will bring for you 50k folders,@Ryan what I meant by my first comment is to distribute your base structure and to make couple of calls at the same time in different threads will help a lot, I can describe more in an answer if this is of your interest – Muhammad Soliman Dec 21 '17 at 02:53
  • a possible solution: use parallel class: https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-iterate-file-directories-with-the-parallel-class – urlreader Dec 21 '17 at 02:54
  • I think, this is a roll own bench mark situation. find the different ways you can enumerate folders, and benchmark them and choose the one most suitable for you. i.e win32 apis ect – TheGeneral Dec 21 '17 at 03:16

0 Answers0