using System.IO; namespace MfGames.IO.Extensions { /// /// Useful extension methods for DirectoryInfo. /// public static class DirectoryInfoExtensions { /// /// Makes sure a directory exists, creating it and any parents above it /// as needed. /// /// public static void CreateIfMissing(this DirectoryInfo? directory) { // Ignore blanks. if (directory == null) { return; } // Check the parent first. We don't have to worry about null because // we check that coming in. directory.Parent.CreateIfMissing(); // If the directory doesn't exist, create it. if (!directory.Exists) { directory.Create(); } } } }