I have an array of FileInfo objects with repeating elements that I would like to filter, i.e. delete duplicates; items are sorted by the last recording time using user matching. The file name format is as follows:
file {number} {} {YYYMMDD HHMMSS} .txt
What I would like to know is an elegant way to filter two files with the same file number so that only the latest one is listed, i.e. I have two elements in my array with the following file names:
file1_20110214_090020.txt
file1_20101214_090020.txt
I would like to keep the latest version of file1 . The code for getting the files is as follows:
FileInfo[] listOfFiles = diSearch.GetFiles(fileSearch);
IComparer compare = new FileComparer(FileComparer.CompareBy.LastWriteTime);
Array.Sort(listOfFiles, compare);
Thank you for your help.
UPDATE:
, , , .Net 2.0, , , LINQ . , ,