DirectoryWrap
Represents a class object wrapper for the Directory class.
using System;
using System.IO;
namespace Relativity.DataExchange.Io
{
[CLSCompliant(false)]
internal class DirectoryWrap : IDirectory
{
private readonly IPath instance;
internal DirectoryWrap(IPath path)
{
if (path == null)
throw new ArgumentNullException("path");
instance = path;
}
public void CreateDirectory(string path)
{
path = instance.NormalizePath(path);
Directory.CreateDirectory(path);
}
public void Delete(string path)
{
path = instance.NormalizePath(path);
Directory.Delete(path);
}
public void Delete(string path, bool recursive)
{
path = instance.NormalizePath(path);
Directory.Delete(path, recursive);
}
public void DeleteIfExists(string path, bool recursive, bool throwOnExistsCheck)
{
if (Exists(path, throwOnExistsCheck))
Delete(path, recursive);
}
public bool Exists(string path)
{
path = instance.NormalizePath(path);
return Directory.Exists(path);
}
public bool Exists(string path, bool throwOnExistsCheck)
{
path = instance.NormalizePath(path);
if (!throwOnExistsCheck)
return Directory.Exists(path);
return Directory.GetCreationTimeUtc(path) != new DateTime(1601, 1, 1);
}
public IDirectoryInfo GetParent(string path)
{
path = instance.NormalizePath(path);
DirectoryInfo parent = Directory.GetParent(path);
if (parent == null)
return null;
return new DirectoryInfoWrap(parent);
}
}
}