示例#1
0
        /// <summary>
        /// Creates a symbolick link to the folder
        /// </summary>
        /// <param name="DstLink">The folder that will receive the link</param>
        /// <param name="overwrite">Whether to overwrite an existing link if present</param>
        /// <remarks>
        /// Adapted from: https://stackoverflow.com/questions/11156754/what-the-c-sharp-equivalent-of-mklink-j
        /// </remarks>
        /// <returns></returns>
        public static Option <FolderSymLink> CreateSymLink(this FolderPath SrcPath, FolderPath DstLink, bool overwrite = true)
        => Try(() =>
        {
            if (overwrite && DstLink.IsLink())
            {
                DstLink.DeleteIfExists().Require();
            }

            var succeeded = SymbolicLinks.CreateSymbolicLink(DstLink, SrcPath.FileSystemPath, SymbolicLinkKind.Directory);
            if (not(succeeded))
            {
                return(none <FolderSymLink>(SymbolicLinkCreationFailed(SrcPath, DstLink)));
            }
            else
            {
                return(new FolderSymLink(SrcPath, DstLink));
            }
        });
示例#2
0
 /// <summary>
 /// Creates a symbolic link to a file
 /// </summary>
 /// <param name="SrcFile">The file to which the link will point</param>
 /// <param name="DstLink">The name of the link</param>
 /// <returns></returns>
 public static Option <FileSymLink> CreateSymLink(this FilePath SrcFile, string DstLink)
 => SymbolicLinks.CreateSymbolicLink(DstLink, SrcFile, SymbolicLinkKind.File) ?
 some(new FileSymLink(SrcFile, DstLink))
           : none <FileSymLink>(error($"The {nameof(CreateSymLink)} call failed"));