예제 #1
0
        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);
        }
예제 #2
0
        /// <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()));
        }
예제 #3
0
 public static void CreateDirectory(this IFileSystem fileSystem, params string[] pathParts)
 {
     fileSystem.CreateDirectory(FileSystem.Combine(pathParts));
 }
예제 #4
0
 public static string ReadStringFromFile(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.ReadStringFromFile(FileSystem.Combine(pathParts)));
 }
예제 #5
0
 public static void PersistToFile(this IFileSystem fileSystem, object target, params string[] pathParts)
 {
     fileSystem.WriteObjectToFile(FileSystem.Combine(pathParts), target);
 }
예제 #6
0
 public static IEnumerable <string> FileNamesFor(this IFileSystem fileSystem, FileSet set, params string[] pathParts)
 {
     return(fileSystem.FindFiles(FileSystem.Combine(pathParts), set));
 }
예제 #7
0
 public static IEnumerable <string> ChildDirectoriesFor(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.ChildDirectoriesFor(FileSystem.Combine(pathParts)));
 }
예제 #8
0
 public static T LoadFromFile <T>(this IFileSystem fileSystem, params string[] pathParts) where T : new()
 {
     return(fileSystem.LoadFromFile <T>(FileSystem.Combine(pathParts)));
 }
예제 #9
0
 public static bool FileExists(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.FileExists(FileSystem.Combine(pathParts)));
 }
예제 #10
0
 public static void LaunchEditor(this IFileSystem fileSystem, params string[] pathParts)
 {
     fileSystem.LaunchEditor(FileSystem.Combine(pathParts));
 }