/// <summary> /// Main Entry Point /// </summary> /// <param name="args">Arguments</param> public static void Main(string[] args) { #if DEBUG args = @"T:\Downloaded\*".Split(' '); #endif //Check for help if (args.Length == 0 || args.Any(m => m == "/?" || m == "--help" || m == "-?")) { Console.Error.WriteLine(@"SmartRename <dir> [...] Renames Files and directories of downloaded media files to something usable. Also deletes unusable files. dir - Directory to rename multiple directories can be specified. You are prompted before each batch of actions. The specified directory must be the one with the unnecessarily stupid name WARNING! ======== Only use if the download was for a video file. Don't use for games or audio albums. Carefully review the pending changes because they can't be undone."); } //Allow processing of multiple directories foreach (var arg in args.SelectMany(m => AyrA.IO.MaskMatch.Match(m, AyrA.IO.MatchType.Directory))) { var Actions = GetSmartNames(arg); if (Actions.Length > 0) { //List all actions for the user to review them foreach (var Action in Actions) { switch (Action.Action) { case SmartAction.None: Console.ForegroundColor = ConsoleColor.Green; Console.Error.WriteLine("Ignore: {0}", ToShort(Action.OldName)); break; case SmartAction.Rename: Console.ForegroundColor = ConsoleColor.Yellow; Console.Error.WriteLine("Rename: {0} --> {1}", ToShort(Action.OldName), ToShort(Action.NewName)); break; case SmartAction.Delete: Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("Delete: {0}", ToShort(Action.OldName)); break; default: throw new NotImplementedException(); } } Console.ResetColor(); if (YN("Execute these actions?")) { foreach (var Act in Actions.Where(m => m.Action != SmartAction.None)) { if (Act.ExecuteAction()) { Console.ForegroundColor = ConsoleColor.Green; Console.Error.WriteLine("{0} OK", Act.Action); } else { Console.ForegroundColor = ConsoleColor.Red; Console.Error.WriteLine("{0} FAIL", Act.Action); Console.Error.WriteLine("OldName: {0}", Act.OldName); Console.Error.WriteLine("NewName: {0}", Act.NewName); } } } Console.ResetColor(); } else { Console.Error.WriteLine($"No actions for {arg}"); } } #if DEBUG Console.Error.WriteLine("#END"); Console.ReadKey(true); #endif }