using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace TxtRemover { class Program { static void Main(string[] args) { string path = args[0]; if (path == "-h") { System.Console.Out.WriteLine("Program do usuwania plików o zduplikowanych nazwach, a innych rozszerzeniach, z zadanego folderu"); System.Console.Out.WriteLine("wywołanie: program.exe "); Environment.Exit(0); } if(!Directory.Exists(path)) { System.Console.Out.WriteLine(string.Format("Katalog {0} nie istnieje!", path)); goto koniec; } string pattern1 = args[1]; string pattern2 = args[2]; System.Console.Out.WriteLine(string.Format("Szukanie plików {0}", pattern1)); var txts = Directory.GetFiles(path, "*."+pattern1); if(txts.Length == 0) { System.Console.Out.WriteLine(string.Format("Brak plików ze wzorca {0} !", pattern1)); goto koniec; } System.Console.Out.WriteLine(string.Format("Znaleziono {0} plików {1}.", txts.Length, pattern1)); Dictionary txts_name_dict = new Dictionary(); System.Console.Out.WriteLine(string.Format("Wyluskiwanie nazw z pelnych sciezek plikow {0}", pattern1)); int i = 1; foreach (var txt in txts) { string NameWithoutPath = Path.GetFileNameWithoutExtension(txt); System.Console.Out.WriteLine(string.Format("{0} {1}/{2}", NameWithoutPath, i++,txts.Length)); txts_name_dict.Add(NameWithoutPath, txt); } System.Console.Out.WriteLine(string.Format("Szukanie plików {0}", pattern2)); var jpgs = Directory.GetFiles(path, "*." + pattern2); if(jpgs.Length == 0) { System.Console.Out.WriteLine(string.Format("Brak plików ze wzorca {0} !", pattern2)); goto koniec; } System.Console.Out.WriteLine(string.Format("Znaleziono {0} plików {1}.", jpgs.Length, pattern2)); System.Console.Out.WriteLine(string.Format("Wyluskiwanie nazw z pelnych sciezek plikow {0}", pattern2)); i = 1; Dictionary jpgs_name_dict = new Dictionary(); foreach(var jpg in jpgs) { string NameWithoutPath = Path.GetFileNameWithoutExtension(jpg); System.Console.Out.WriteLine(string.Format("{0} {1}/{2}", NameWithoutPath, i++, jpgs.Length)); jpgs_name_dict.Add(NameWithoutPath, jpg); } System.Console.Out.WriteLine(string.Format("Usuwanie plikow asymetrycznych wzgledem zbiorow {0} i {1}", pattern1, pattern2)); foreach (var txtPair in txts_name_dict) { if(!jpgs_name_dict.ContainsKey(txtPair.Key)) { System.Console.Out.WriteLine(string.Format("Usuwanie {0}",txtPair.Value)); File.Delete(txtPair.Value); } else { System.Console.Out.WriteLine(string.Format("Plik {0} OK!", txtPair.Key)); } } koniec: System.Console.Out.WriteLine(string.Format("Zakonczono prace, nacisnij dowolny klawisz by wyjsc...")); System.Console.ReadKey(); } } }