public static void ShowCopyAndRenameConfig() { if (!File.Exists(_configFile)) { OutLineFormat("{0} file not found, beginning configuration.", ConsoleColor.Yellow, _configFile); ConfigureCopyAndRename(); } else { RenCopyConfig config = File.ReadAllText(_configFile).FromJson <RenCopyConfig>(); OutLineFormat("SrcFolder: {0}", ConsoleColor.Cyan, config.SourceFolder); OutLineFormat("DstFolder: {0}", ConsoleColor.Cyan, config.TargetFolder); OutLineFormat("\t*** extensions\r\n"); foreach (string ext in config.TextReplacementFileExtensions) { OutLineFormat("\t{0}", ConsoleColor.Magenta, ext); } OutLineFormat("\t*** copy extensions\r\n"); foreach (string ext in config.CopyExtensions) { OutLineFormat("\t{0}\r\n", ConsoleColor.Blue, ext); } OutLineFormat("\t*** replacements\r\n"); foreach (TextReplacement r in config.TextReplacements) { OutLineFormat("\told: {0}, new: {1}", ConsoleColor.Yellow, r.OldText, r.NewText); } OutLineFormat("\t*** ignore patterns (for files and folders)"); foreach (string ignore in config.Ignore) { OutLineFormat("\t{0}", ignore); } } }
public static void ConfigureCopyAndRename() { List <string> textReplacementFileExtensions = new List <string>(); List <string> copyExtensions = new List <string>(); string answer = ""; while (!answer.Equals("done")) { if (!string.IsNullOrEmpty(answer)) { textReplacementFileExtensions.Add(answer); } answer = GetTextReplacementExtension(); } answer = GetCopyFileExtension(); bool copyAll = false; if (answer.ToLowerInvariant().Equals("all")) { copyAll = true; } else { while (!answer.Equals("done")) { if (!string.IsNullOrEmpty(answer)) { copyExtensions.Add(answer); } answer = GetCopyFileExtension(); } } List <TextReplacement> textReplacements = new List <TextReplacement>(); TextReplacement replacement = new TextReplacement("", ""); while (replacement != null) { if (!string.IsNullOrEmpty(replacement.OldText)) { textReplacements.Add(replacement); } replacement = GetTextReplacement(); } string sourceFolder = Prompt("Enter the source folder path"); string targetFolder = Prompt("Enter the target folder path"); RenCopyConfig config = new RenCopyConfig(); config.SourceFolder = sourceFolder; config.TargetFolder = targetFolder; config.TextReplacementFileExtensions = textReplacementFileExtensions.ToArray(); config.CopyExtensions = copyExtensions.ToArray(); config.CopyAllFiles = copyAll; config.TextReplacements = textReplacements.ToArray(); config.ToJsonFile(_configFile); if (Confirm("Copy files now?")) { CopyAndRename(); } }