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)); } } }
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); }
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"); } }
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); } }
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(); }
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"); } }
public static IEnumerable <PathName> EnumerateDirectories(this PathName path) { return(Directory.EnumerateDirectories(path.Full).Select(filePath => PathName.Path(filePath))); }
public static bool ExistsDirectory(this PathName path) { return(Directory.Exists(path.Full)); }
public static void CreateDirectory(this PathName path) { Directory.CreateDirectory(path.Full); }
public static void MoveDirectory(this PathName source, PathName destination) { Directory.Move(source.Full, destination.Full); }
public static FileNotFoundException EntityDoesntExists(PathName path) { return(new FileNotFoundException($"'{path}' doesn't exists as expected")); }
public static void CopyFileFrom(this PathName destination, PathName source) { File.Copy(source.Full, destination.Full); }
public static DirectoryNotFoundException DirectoryNotFoundException(PathName path) { return(new DirectoryNotFoundException($"expected directory '{path}', but it doesn't exists")); }
public static void WriteAllBytes(this PathName path, byte[] bytes) { File.WriteAllBytes(path.Full, bytes); }
internal abstract PathName Join(PathName other);
public static bool ExistsFile(this PathName path) { return(File.Exists(path.Full)); }
public static string[] ReadAllLines(this PathName path) { return(File.ReadAllLines(path.Full)); }
public static FileNotFoundException EntityExistsButIsNotDirectory(PathName path) { return(new FileNotFoundException($"'{path}' exists, but isn't a directory as expected")); }
public static void DeleteDirectory(this PathName path, bool recursive = false) { Directory.Delete(path.Full, recursive); }
public static FileNotFoundException FileNotFoundException(PathName path) { return(new FileNotFoundException($"expected file '{path}', but it doesn't exists")); }
public static void DeleteFile(this PathName path) { File.Delete(path.Full); }