35 lines
935 B
C#
35 lines
935 B
C#
using System.IO;
|
|
|
|
namespace MfGames.IO.Extensions
|
|
{
|
|
/// <summary>
|
|
/// Useful extension methods for DirectoryInfo.
|
|
/// </summary>
|
|
public static class DirectoryInfoExtensions
|
|
{
|
|
/// <summary>
|
|
/// Makes sure a directory exists, creating it and any parents above it
|
|
/// as needed.
|
|
/// </summary>
|
|
/// <param name="directory"></param>
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|