private void renameNew(string[] files, ProgressBarWindow pbw) { string epName; for (int file = 0; file < files.Count(); file++) { for (int season = 0; season < namesCount; season++) { for (int episode = 0; episode < namesCount; episode++) { for (int variability = 0; variability < 3; variability++) { for (int ext = 0; ext < 10; ext++) { if (files[file].IndexOf(names[season, episode, variability], StringComparison.OrdinalIgnoreCase) >= 0 && files[file].IndexOf(fileExtension[ext], StringComparison.OrdinalIgnoreCase) >= 0) { epName = getName(season + 1, episode + 1); if (!files[file].Contains(epName) && Path.GetDirectoryName(files[file]) != defLoc + "Season???") { if (Int32.Parse(Properties.Settings.Default["Danger"].ToString()) == 1) { try { File.Move(files[file], pathMove(season, fileExtension[ext], epName)); } catch (IOException) { MessageBox.Show("Check if file is not being used!"); } } else { File.Move(files[file], pathMove(season, fileExtension[ext], epName)); } Dispatcher.Invoke(new Action(() => { pbw.bar.Value = 100 * ((float)file / (float)files.Count()); }), DispatcherPriority.Send); } } } } } } } Dispatcher.Invoke(new Action(() => { pbw.bar.Value = 100; }), DispatcherPriority.Send); }