Beispiel #1
0
 public static PathName operator/(PathName left, PathName right)
 {
     if (left != null)
     {
         if (right != null) // left != null && right != null;
         {
             return(left.Join(right));
         }
         else // left != null &&  right == null
         {
             return(left);
         }
     }
     else // left == null
     {
         if (right != null) // left == null && right != null
         {
             return(right);
         }
         else // left == null && right == null
         {
             return(PathName.Path(null));
         }
     }
 }
Beispiel #2
0
 public static void TouchFile(this PathName path)
 {
     if (!File.Exists(path.Full))
     {
         using (var stream = File.OpenWrite(path.Full))
         {
             stream.Close();
         }
     }
     Debug.Assert(File.Exists(path.Full));
     File.SetLastWriteTime(path.Full, DateTime.Now);
 }
Beispiel #3
0
 internal override PathName Join(PathName right)
 {
     if (right is PosixPathName other)
     {
         if (other.IsAbsolute)
         {
             return(right);
         }
         return(new PosixPathName(this.lead, this.segments.Concat(other.segments)));
     }
     else
     {
         throw new InvalidOperationException("can't join posix-path with non-posix-path");
     }
 }
Beispiel #4
0
        public static void RemoveDirectory(PathName directory)
        {
            if (!directory.ExistsDirectory())
            {
                if (directory.ExistsFile())
                {
                    throw PathNameErrors.EntityExistsButIsNotDirectory(directory);
                }
                throw PathNameErrors.DirectoryNotFoundException(directory);
            }

            using (var progress = new Progress())
            {
                RemoveDirectory(directory, progress);
            }
        }
Beispiel #5
0
        private static void RemoveDirectory(PathName directory, Progress progress)
        {
            foreach (var file in directory.EnumerateFiles())
            {
                file.DeleteFile();
                progress.Advance();
            }

            foreach (var child in directory.EnumerateDirectories())
            {
                RemoveDirectory(child, progress);
            }

            directory.DeleteDirectory();
            progress.Advance();
        }
Beispiel #6
0
 internal override PathName Join(PathName right)
 {
     if (right is WindowsPathName other)
     {
         if (other.IsAbsolute)
         {
             return(other);
         }
         else if (other.IsAnchored)
         {
             throw new InvalidOperationException("can't join windows-path with anchored windows-path");
         }
         return(new WindowsPathName(this.lead, this.segments.Concat(other.segments)));
     }
     else
     {
         throw new InvalidOperationException("can't join windows-path with non-windows-path");
     }
 }
Beispiel #7
0
 public static IEnumerable <PathName> EnumerateDirectories(this PathName path)
 {
     return(Directory.EnumerateDirectories(path.Full).Select(filePath => PathName.Path(filePath)));
 }
Beispiel #8
0
 public static bool ExistsDirectory(this PathName path)
 {
     return(Directory.Exists(path.Full));
 }
Beispiel #9
0
 public static void CreateDirectory(this PathName path)
 {
     Directory.CreateDirectory(path.Full);
 }
Beispiel #10
0
 public static void MoveDirectory(this PathName source, PathName destination)
 {
     Directory.Move(source.Full, destination.Full);
 }
Beispiel #11
0
 public static FileNotFoundException EntityDoesntExists(PathName path)
 {
     return(new FileNotFoundException($"'{path}' doesn't exists as expected"));
 }
Beispiel #12
0
 public static void CopyFileFrom(this PathName destination, PathName source)
 {
     File.Copy(source.Full, destination.Full);
 }
Beispiel #13
0
 public static DirectoryNotFoundException DirectoryNotFoundException(PathName path)
 {
     return(new DirectoryNotFoundException($"expected directory '{path}', but it doesn't exists"));
 }
Beispiel #14
0
 public static void WriteAllBytes(this PathName path, byte[] bytes)
 {
     File.WriteAllBytes(path.Full, bytes);
 }
Beispiel #15
0
 internal abstract PathName Join(PathName other);
Beispiel #16
0
 public static bool ExistsFile(this PathName path)
 {
     return(File.Exists(path.Full));
 }
Beispiel #17
0
 public static string[] ReadAllLines(this PathName path)
 {
     return(File.ReadAllLines(path.Full));
 }
Beispiel #18
0
 public static FileNotFoundException EntityExistsButIsNotDirectory(PathName path)
 {
     return(new FileNotFoundException($"'{path}' exists, but isn't a directory as expected"));
 }
Beispiel #19
0
 public static void DeleteDirectory(this PathName path, bool recursive = false)
 {
     Directory.Delete(path.Full, recursive);
 }
Beispiel #20
0
 public static FileNotFoundException FileNotFoundException(PathName path)
 {
     return(new FileNotFoundException($"expected file '{path}', but it doesn't exists"));
 }
Beispiel #21
0
 public static void DeleteFile(this PathName path)
 {
     File.Delete(path.Full);
 }