c# - processing a list in an elegant and quick manner for duplicates -


di have below code check existance of duplicate filename , deleting files duplicates.

i can looking first , last index in first list checking if it's not same. list item contains object name , id. there around 550k objects in list.

the second loop has filespaths list around 5k filepaths. if theres duplicate file , in second list can delete.

the below operation takes on day complete. there way shorten time?

foreach (docnameobject someobjectdatafilerow in someobjectdatafilelist) {      int index1 = array.findindex(someobjectdatafilelist.toarray(), row => row.docname.startswith(someobjectdatafilerow.docname));   int index2 = array.findlastindex(someobjectdatafilelist.toarray(), row => row.docname.startswith(someobjectdatafilerow.docname));    console.writeline(++i);   if (index1 != index2)    {     foreach (string filename in filespaths)        {          try          {             if (filename.contains(someobjectdatafilerow.docname))             {                if (file.exists(filename))                  file.delete(filename);             }          }catch (exception e)          {             console.writeline("problem deleting:" + e.message);          }        }      } } 

the first thing sort "someobjectdatafilelist" based on docname. might make computation of index1 , index2 redundant.

another optimization delete filename 'filepaths' list, once physically deleted.


Comments