Posts System.IO.Directory.GetFiles() Alternative

System.IO.Directory.GetFiles() Alternative

If you’ve ever wanted to do something a bit more custom with System.IO.Directory.GetFiles() or System.IO.Directory.GetDirectories(), the typical hack is to write a wrapper around the “*.*” version. Well, there is an alternative; quite literally. Marijan Nikic posted a great re-write on CodeProject that is directly manipulating the WinAPI. He used the namespace System.IO.DirectoryAlternative so its quite natural to implement. Not only does this give you all the inner workings that you might want to manipulate in a single *.CS file, but it actually functions quite a bit faster than the native .Net version too. That CodeProject Article contains a comment stating the native version has a caching advantage, but that wouldn’t matter for most of my use cases.

My only gripe is that it isn’t on GitHub where it could be expanded and I always struggle to find it until I do my search directly within CodeProject. So, I am somewhat writing this post just so I remember where to find it.

This post is licensed under CC BY 4.0 by the author.