Пример #1
0
        private void MklinkDir(string dir)
        {
            var dirName   = Path.GetFileName(dir);
            var targetDir = $"{TargetFolder}\\{dirName}";

            _logBuilder.Append(dirName);

            if (IgnorePath.Contains(dirName, StringComparer.OrdinalIgnoreCase))
            {
                _logBuilder.AppendLine(" >>>忽略");
            }
            else
            {
                if (Directory.Exists(targetDir))
                {
                    Directory.Delete(targetDir, false);
                }
                if (CreateSymbolicLink(targetDir, dir, SymbolicLink.Directory))
                {
                    _logBuilder.AppendLine(" >>>映射成功");
                }
                else
                {
                    _logBuilder.AppendLine(" >>>映射失败!!!");
                }
            }

            AppendLog();
        }
Пример #2
0
        private void MklinkFile(string file)
        {
            var fileName   = Path.GetFileName(file);
            var targetFile = $"{TargetFolder}\\{fileName}";

            _logBuilder.Append(fileName);

            if (IgnorePath.Contains(fileName, StringComparer.OrdinalIgnoreCase))
            {
                _logBuilder.AppendLine(" >>>忽略");
            }
            else if (ActualFiles.Contains(fileName, StringComparer.OrdinalIgnoreCase))
            {
                try
                {
                    DeleteFile(targetFile);
                    File.Copy(file, targetFile);
                    _logBuilder.AppendLine(" >>>复制成功");
                }
                catch (Exception e)
                {
                    _logBuilder.AppendLine(" >>>复制失败!!!");
                    Logger.Error("复制文件错误", e);
                }
            }
            else
            {
                try
                {
                    DeleteFile(targetFile);
                    if (CreateSymbolicLink(targetFile, file, SymbolicLink.File))
                    {
                        _logBuilder.AppendLine(" >>>映射成功");
                    }
                    else
                    {
                        _logBuilder.AppendLine(" >>>映射失败!!!");
                    }
                }
                catch (Exception e)
                {
                    _logBuilder.AppendLine(" >>>映射失败!!!");
                    Logger.Error("映射文件错误", e);
                }
            }

            AppendLog();
        }