Example #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);
        }
Example #2
0
        public static string PathRelativeTo(this string path, string root)
        {
            var pathParts = path.Split(Path.DirectorySeparatorChar).ToList();
            var rootParts = root.Split(Path.DirectorySeparatorChar).ToList();

            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(FileSystem.Combine(pathParts.ToArray()));
        }
Example #3
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()));
        }
Example #4
0
        public void MoveFiles(string from, string to)
        {
            var files = Directory.GetFiles(from, "*.*", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                var partialPath = file.Replace(from, "");
                if (partialPath.StartsWith(@"\"))
                {
                    partialPath = partialPath.Substring(1);
                }
                var newPath = FileSystem.Combine(to, partialPath);
                MoveFile(file, newPath);
            }
        }
Example #5
0
 public static string ReadStringFromFile(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.ReadStringFromFile(FileSystem.Combine(pathParts)));
 }
Example #6
0
 public static IEnumerable <string> FileNamesFor(this IFileSystem fileSystem, FileSet set, params string[] pathParts)
 {
     return(fileSystem.FindFiles(FileSystem.Combine(pathParts), set));
 }
Example #7
0
 public static IEnumerable <string> ChildDirectoriesFor(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.ChildDirectoriesFor(FileSystem.Combine(pathParts)));
 }
Example #8
0
 public static T LoadFromFile <T>(this IFileSystem fileSystem, params string[] pathParts) where T : new()
 {
     return(fileSystem.LoadFromFile <T>(FileSystem.Combine(pathParts)));
 }
Example #9
0
 public static bool FileExists(this IFileSystem fileSystem, params string[] pathParts)
 {
     return(fileSystem.FileExists(FileSystem.Combine(pathParts)));
 }
Example #10
0
 public static void LaunchEditor(this IFileSystem fileSystem, params string[] pathParts)
 {
     fileSystem.LaunchEditor(FileSystem.Combine(pathParts));
 }
Example #11
0
 public static void CreateDirectory(this IFileSystem fileSystem, params string[] pathParts)
 {
     fileSystem.CreateDirectory(FileSystem.Combine(pathParts));
 }
Example #12
0
 public static void PersistToFile(this IFileSystem fileSystem, object target, params string[] pathParts)
 {
     fileSystem.WriteObjectToFile(FileSystem.Combine(pathParts), target);
 }