alphaleonis / AlphaFS

AlphaFS is a .NET library providing more complete Win32 file system functionality to the .NET platform than the standard System.IO classes.
http://alphafs.alphaleonis.com/
MIT License
563 stars 99 forks source link

Add overloaded methods that use enumerating to support the DirectoryEnumerationFilters argument. #390

Closed Yomodo closed 6 years ago

Yomodo commented 6 years ago

Enumerating folders/files can raise error 5: Access Denied Exceptions.

Using DirectoryEnumerationFilters enumerating can report these exceptions and continue.

Added bonus is additional folder/file criteria filtering: Example/Unit Test

RandomSheeple commented 6 years ago

Pardon my ignorance in case this question is silly, but how would this play out with .net existing error handling methodologies? Specifically parallel.foreach when run from a task factory does not allow for exception handling in there without dying a horrible messy convoluted death when enumerating 100 000's of folders and millions of files in parallel. Currently I am running into these errors in a await Task.Factory.StartNew(() => Parallel.ForEach(rootFolders, (currentFolder) => { try { //do something with Alphaleonis.Win32.Filesystem.DirectoryInfo.GetDirectories(); //that causes exception (mambo) #5 like try to access recycle bin, volume info etc } catch (Exception ex) { ExceptionQ.Enqueue(ex); } })); When queuing up errors in a ConcurrentQueue I can just handle them in a managed way single thread in the caller after all is done.

ref: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/how-to-handle-exceptions-in-parallel-loops

Yomodo commented 6 years ago

The AlphaFS .NET implementations will remain as-is.

I haven't tried the DirectoryEnumerationFilters yet in a parallel context, so I'm not sure how that will turn out. For "normal" processing, these filters work well.