public static List <string> FindSimilarNames(string path, string[] types, string[] otherFiles, out bool nameHasSuffix, out string pathWithoutSuffix) { // parse the file pathWithoutSuffix = null; nameHasSuffix = FindPathWithSuffixRemoved(path, types, out pathWithoutSuffix); // delete all the rest in group var nameWithoutSuffix = nameHasSuffix ? pathWithoutSuffix : path; List <string> results = new List <string>(); foreach (var otherFile in otherFiles) { if (otherFile.ToUpperInvariant() != path.ToUpperInvariant()) { if (FilenameUtils.SameExceptExtension(nameWithoutSuffix, otherFile) || (FindPathWithSuffixRemoved(otherFile, types, out string nameMiddleRemoved) && FilenameUtils.SameExceptExtension(nameWithoutSuffix, nameMiddleRemoved))) { results.Add(otherFile); } } } return(results); }
static void TestMethod_UtilsSameExceptExtension() { TestUtil.IsTrue(FilenameUtils.SameExceptExtension( "test6.jpg", "test6.jpg")); TestUtil.IsTrue(FilenameUtils.SameExceptExtension( "test6.jpg", "test6.png")); TestUtil.IsTrue(FilenameUtils.SameExceptExtension( "test6.jpg", "test6.BMP")); TestUtil.IsTrue(!FilenameUtils.SameExceptExtension( "test6.jpg", "test6.jpg.jpg")); TestUtil.IsTrue(!FilenameUtils.SameExceptExtension( "test6a.jpg", "test6.jpg")); TestUtil.IsTrue(FilenameUtils.SameExceptExtension( "aa.jpg.test6.jpg", "aa.jpg.test6.bmp")); TestUtil.IsTrue(!FilenameUtils.SameExceptExtension( "aa.jpg.test6.jpg", "aa.bmp.test6.jpg")); TestUtil.IsTrue(FilenameUtils.SameExceptExtension( PathSep("a/test6.jpg"), PathSep("a/test6.jpg"))); TestUtil.IsTrue(!FilenameUtils.SameExceptExtension( PathSep("a/test6.jpg"), PathSep("b/test6.jpg"))); }