C# – Find all empty folders

An empty folder: Has no files. Either has no folders, or has folders that are empty. In this article I’ll show code that finds empty folders based on this definition. Code that finds empty folders Given a root folder path, the following code recursively looks for empty folders and writes the empty folder path to … Read more C# – Find all empty folders

Event-driven .NET: use FileSystemWatcher instead of polling for new files

You can use FileSystemWatcher to get notified of file system changes, such as when a file is created. Here’s an example of reacting to when a JSON file is created: Compared to polling, this event-driven approach with FileSystemWatcher is more efficient and simpler. In the remainder of this article I’ll show an example of how … Read more Event-driven .NET: use FileSystemWatcher instead of polling for new files

C# – How to unit test async methods

Let’s say you have the following async method you want to test: Here’s how to unit test this: This is awaiting the method you’re testing. To await it, you must make the unit test method return async Task. This example is a bit simplistic. In the real world when you are working with async methods, … Read more C# – How to unit test async methods