/// <summary> /// Creates the specified director junction. /// Creates all the directories in the specified path. /// </summary> /// <param name="path">The directory junction to create.</param> /// <param name="destination">The destination of the junction.</param> public static void Create(string path, string destination) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (string.IsNullOrEmpty(destination)) { throw new ArgumentNullException(nameof(destination)); } if (Junction.Exists(path)) { destination = Path.GetFullPath(destination); SetDestination(path, destination); } else if (File.Exists(path)) { throw new InvalidOperationException($"The path '{path}' already exists but points to a file."); } else if (Directory.Exists(path)) { throw new InvalidOperationException($"The path '{path}' already exists but points to a directory."); } else { Directory.CreateDirectory(path); destination = Path.GetFullPath(destination); SetDestination(path, destination); } }
/// <summary> /// Deletes a specified directory junction. /// </summary> /// <param name="path">The name of the directory junction to remove.</param> public static void Delete(string path) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (!Junction.Exists(path)) { throw new IOException($"The path '{path}' does not exist or does not point to a valid directory junction."); } Kernel32.RemoveDirectory(path); }