welcome the essence of the question in the title. There is an application that scans a folder each time you log in for extra files. extras are those that are not defined in the list. actually:
private void DeleteFILES(DAL dal) { List<string> Equals = new List<string>(); for (int i = 0; i < dal.getMNamesfromBD().Count; i++) { Equals.Add(dal.getMNamesfromBD()[i].ToString()); } try { string CompletePatchToEXE = Directory.GetCurrentDirectory(); DirectoryInfo dir = new DirectoryInfo(CompletePatchToEXE + @"\\materials\\"); foreach (FileInfo file in dir.GetFiles()) { for (int i=0; i<dal.getMNamesfromBD().Count; i++) { if (file.Name != Equals[i]+ ".jpg") { file.Delete(); } } } MessageBox.Show("Файлы поставленные в очереди были успешно удалены!", "Редактирование"); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } } however, instead of deleting files that are not registered in Equals, the code deletes all files altogether. I can not find a mistake, tell me where to fix it? thank!
if (file.Name != Equals[i]+ ".jpg")in a loop where you can’t write an action at the same time. this is the line with the error - nick_n_aListand makeList.IndexOf() < 02) use bool moisture, instead of deleting in a loop dokeepFile=true;and after the cycleif (!keepFile) delete- nick_n_a>=0you will know that the element is in the list. And you can remove the verification cycle. (But then there will be a cycle that will fill the list) - nick_n_a