public static string PathRelativeTo(this string path, string root) { var pathParts = path.getPathParts(); var rootParts = root.getPathParts(); var length = pathParts.Count > rootParts.Count ? rootParts.Count : pathParts.Count; for (int i = 0; i < length; i++) { if (pathParts.First() == rootParts.First()) { pathParts.RemoveAt(0); rootParts.RemoveAt(0); } else { break; } } for (int i = 0; i < rootParts.Count; i++) { pathParts.Insert(0, ".."); } return(pathParts.Count > 0 ? FileSystem.Combine(pathParts.ToArray()) : string.Empty); }
/// <summary> /// Equivalent of FileSystem.Combine( [Union of path, parts] ) /// </summary> /// <param name="path"></param> /// <param name="parts"></param> /// <returns></returns> public static string AppendPath(this string path, params string[] parts) { var list = new List <string> { path }; list.AddRange(parts); return(FileSystem.Combine(list.ToArray())); }
public static void CreateDirectory(this IFileSystem fileSystem, params string[] pathParts) { fileSystem.CreateDirectory(FileSystem.Combine(pathParts)); }
public static string ReadStringFromFile(this IFileSystem fileSystem, params string[] pathParts) { return(fileSystem.ReadStringFromFile(FileSystem.Combine(pathParts))); }
public static void PersistToFile(this IFileSystem fileSystem, object target, params string[] pathParts) { fileSystem.WriteObjectToFile(FileSystem.Combine(pathParts), target); }
public static IEnumerable <string> FileNamesFor(this IFileSystem fileSystem, FileSet set, params string[] pathParts) { return(fileSystem.FindFiles(FileSystem.Combine(pathParts), set)); }
public static IEnumerable <string> ChildDirectoriesFor(this IFileSystem fileSystem, params string[] pathParts) { return(fileSystem.ChildDirectoriesFor(FileSystem.Combine(pathParts))); }
public static T LoadFromFile <T>(this IFileSystem fileSystem, params string[] pathParts) where T : new() { return(fileSystem.LoadFromFile <T>(FileSystem.Combine(pathParts))); }
public static bool FileExists(this IFileSystem fileSystem, params string[] pathParts) { return(fileSystem.FileExists(FileSystem.Combine(pathParts))); }
public static void LaunchEditor(this IFileSystem fileSystem, params string[] pathParts) { fileSystem.LaunchEditor(FileSystem.Combine(pathParts)); }