/// <summary> /// Move a file to the destination, then put a symlink in the original location /// pointing to the destination copy. /// </summary> /// <param name="sourcePath"></param> /// <param name="destinationPath"></param> public static IFileLocation MoveAndLink(this IFileLocation source, IFileLocation destination) { // If the destination is null, return null if (destination == null) return null; // Make sure you don't try to copy over yourself if (source.FullName.Equals(destination.FullName)) return source; // If you're a symbolic link, don't move anything, as you don't have anything real to move. // The symbolic link is probably there because this method was called previously // and if you move the link, it will break, accomplishing nothing useful. // If you're an actual file, move it to the destination if (!source.Attributes.HasFlag(FileAttributes.ReparsePoint)) source.MoveTo(destination); // Then put a symlink in the place of the source pointing to the destination destination.RelativeSymlinkTo(source); return destination; }