public void CreateDirectory(string path)
{
//because a call to this method can actually create multiple diretories,
// we need to find out explicitly which are being created, and add a
// journal entry for each.
string strNormalizedPath = m_rgxCleanPath.Replace(Path.GetFullPath(path), Path.DirectorySeparatorChar.ToString());
strNormalizedPath = strNormalizedPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
string[] strPaths = strNormalizedPath.Split(Path.DirectorySeparatorChar);
Int32 i = 0;
string strPath = "";
if (strPaths[0].EndsWith(Path.VolumeSeparatorChar.ToString()))
{
strPath = strPaths[0] + Path.DirectorySeparatorChar;
i++;
}
for (; i < strPaths.Length; i++)
{
//if we don't have write permission to the parent directory, then whether
// or not the child directory exists is irrelevant, as we won't be able to create it
try
{
FileIOPermission fipWritePermission = new FileIOPermission(FileIOPermissionAccess.Write, strPath);
strPath = Path.Combine(strPath, strPaths[i]);
fipWritePermission.Demand();
if (!Directory.Exists(strPath))
{
var r = new RollbackDirectory(strPath);
try
{
Directory.CreateDirectory(strPath);
}
catch (Exception e)
{
r.CleanUp();
throw new Exception(e.Message, e);
}
if (_tx != null)
{
_journal.Add(r);
Enlist();
}
}
}
catch (SecurityException)
{
}
}
}