I have a list of filenames like:
helloworld#123.xml
hi.xml
test#1.xml
thisguyrighthere.xml
The program I'm designing will use this list(newFileList) to compare to another list(existingFileList) for duplicates. When I run the program, it will search the existingFileLists with a binary search(they are actually large lists) and remove from the newFileList as they are found. After the newFileList has been trimmed down, it will add remaining elements to the existingFileList. So if I ran the program twice with the exact same newFileList, the newFileList should be empty after the end of this process.
The issue I'm having(code to be shown below), is that the first element is not being removed from the newFileList and is repeatedly being added to existingFileList and produces a file contains these lines (the last line is repeated depending on how many times the program is run):
helloworld#123.xml
hi.xml
test#1.xml
thisguyrighthere.xml
helloworld#123.xml
Here are the relevant code snippets:
public class FileName : IComparable<FileName>
{
public string fName { get; set; }
public int CompareTo(FileName other)
{
return fName.CompareTo(other.fName);
}
}
public static void CheckLists(List<FileName> newFileList, List<FileName> existingFileList)
{
for (int i = newFileList.Count - 1; i>-1; i--)
{
if (existingFileList.BinarySearch(newFileList[i]) > 0)
{
newFileList.Remove(newFileList[i]);
}
}
}
The purpose for this process is to grab a list of files from an FTP and copy them to another FTP while preventing duplicates. If someone can think of a better way(I've tried a couple and this seemed to be the fastest so far), I'd be open to changing the way this all works. Any help would be greatly appreciated!