コード例 #1
0
ファイル: Folder.ext.cs プロジェクト: 0xCM/Meta.Core
        /// <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
ファイル: Folder.ext.cs プロジェクト: 0xCM/Meta.Core
 /// <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
        );