26 namespace Ntp.Common.IO
30 private static readonly
object Locker =
new object();
34 int pos1 = file.LastIndexOf(Path.DirectorySeparatorChar);
35 int pos2 = file.LastIndexOf(Path.AltDirectorySeparatorChar);
37 int pos = pos1 > pos2 ? pos1 : pos2;
41 string path = file.Substring(0, pos);
42 return CreateRecursive(path);
50 string fullPath = path.Trim();
57 fullPath = fullPath.TrimEnd().
58 TrimEnd(Path.DirectorySeparatorChar).
59 TrimEnd(Path.AltDirectorySeparatorChar);
60 }
while (lastPath != fullPath);
62 if (fullPath.Length <= 1)
66 string created = null;
67 char[]
s = {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
68 var elements = fullPath.Split(s, StringSplitOptions.RemoveEmptyEntries).ToList();
70 if (elements.Count <= 1)
74 string currentPath = elements[0];
78 if (path.Trim()[0] == Path.DirectorySeparatorChar || path.Trim()[0] == Path.AltDirectorySeparatorChar)
79 currentPath = Path.DirectorySeparatorChar + currentPath;
82 foreach (
string element in elements)
84 currentPath = $
"{currentPath}{Path.DirectorySeparatorChar}{element}";
85 if (Directory.Exists(currentPath))
88 Directory.CreateDirectory(currentPath);
89 created = currentPath;
static string CreateRecursive(string path)
static string CreateRecursiveFromFile(string file)