private List <string> GetUniquePaths() { Debug.WriteLine("GetUniquePaths():"); List <string> tempList = new List <string>(); //List<string> searchList = new List<string>(); var sortedList = MyFolders.OrderBy(x => x.Length).Distinct().ToList(); //searchList = sortedList.ToList(); if (sortedList.Count() == 1) { Debug.Print(sortedList[0]); return(sortedList); } else { for (int i = 0; i < sortedList.Count() - 1; i++) { for (int j = i + 1; j < sortedList.Count; j++) { Debug.Print("---"); Debug.WriteLine(sortedList[i]); Debug.WriteLine(sortedList[j]); if (sortedList[j].Contains(sortedList[i])) { tempList.Add(sortedList[j]); Debug.Print(":"); Debug.Print(string.Join("\n", tempList)); Debug.Print(":"); } } } Debug.Print("=== tempList ==="); foreach (var item in tempList) { Debug.Print(item); sortedList.Remove(item); } Debug.Print("=== sortedList ==="); Debug.Print(string.Join("\n", sortedList)); return(sortedList); } }