public static void Main(string[] args) { if (2 != args.Length) { Console.WriteLine("RenameAndMoveMusic [source directory] [destination directory]"); return; } var sourceDir = args[0].Normalize(); var destinationDir = args[1].Normalize(); try { foreach (var path in Program.GetAllMP3AndM4AFiles(sourceDir)) { try { var songInformation = new SongInformation(path); /*Console.WriteLine( @"{0} Album: {1} Artist: {2} Title: {3} Track: {4} IsCompilation: {5}", path, songInformation.Album, songInformation.Artist, songInformation.Title, songInformation.Track, songInformation.IsCompilation);*/ var placement = new Placement(songInformation); /*foreach (var dir in placement.ParentDirs) Console.WriteLine("\t\t" + dir); Console.WriteLine("\t\t" + placement.Filename);*/ Program.Move(destinationDir, path, placement); } catch (Exception e) { Console.WriteLine("Problem with " + path); var ex = e; do { Console.WriteLine(ex); ex = ex.InnerException; } while (null != ex); } } Program.Clean(destinationDir); } catch (Exception e) { var ex = e; do { Console.WriteLine(ex); ex = ex.InnerException; } while (null != ex); } }
/// <summary> /// Moves the file based on instructions in the placement /// </summary> private static void Move(string destinationDir, string path, Placement placement) { var destinationPath = destinationDir; foreach (var dir in placement.ParentDirs) { destinationPath = Path.Combine(destinationPath, dir).Normalize(); Program.VerifyPath(destinationPath); } destinationPath = Path.Combine(destinationPath, placement.Filename).Normalize(); if (path.ToLowerInvariant() != destinationPath.ToLowerInvariant()) { Console.WriteLine( "Moving\n\tFrom: {0}\n\tTo: {1}", path, destinationPath); File.Move( sourceFileName: path, destFileName: destinationPath); } }