Beispiel #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));
            }
        });
Beispiel #2
0
 /// <summary>
 /// Creates a folder, overwriting anything that currently exists
 /// </summary>
 /// <returns></returns>
 public static Option <FolderPath> Recreate(this FolderPath folder)
 => Try(() =>
        from x in folder.DeleteIfExists()
        from y in folder.CreateIfMissing()
        select y
        );