public void GetDirectorySegmentsTest() { Assert.AreEqual(0, root.GetDirectorySegments().Length); Directories .Where(d => !d.IsRoot) .All(d => d.GetDirectorySegments().Length == d.ParentPath.GetDirectorySegments().Length - 1); Files.All(f => f.GetDirectorySegments().Length == f.ParentPath.GetDirectorySegments().Length); }
public void GetDirectorySegmentsTest() { Assert.Empty(_root.GetDirectorySegments()); // ReSharper disable ReturnValueOfPureMethodIsNotUsed Directories .Where(d => !d.IsRoot) .All(d => d.GetDirectorySegments().Length == d.ParentPath.GetDirectorySegments().Length - 1); Files.All(f => f.GetDirectorySegments().Length == f.ParentPath.GetDirectorySegments().Length); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
public static void CreateDirectoryRecursive(this IFileSystem fileSystem, FileSystemPath path) { if (!path.IsDirectory) throw new ArgumentException("The specified path is not a directory."); var currentDirectoryPath = FileSystemPath.Root; foreach(var dirName in path.GetDirectorySegments()) { currentDirectoryPath = currentDirectoryPath.AppendDirectory(dirName); if (!fileSystem.Exists(currentDirectoryPath)) fileSystem.CreateDirectory (currentDirectoryPath); } }