使用SymmetricDifference比较两个不同文件的文件夹?

时间:2010-12-13 09:11:17

标签: c# linq

我正在比较具有对称差异的非相同文件的两个文件夹,并将长度和目录名称写入文本文件......但它写得像

5506       D:\Trial\codegenpath\ramcovm247_portal_765\EDKPLAjaxCodeGen.log
5857       D:\Trial\codegenpath\ramcovm247_portal_765\EDKService.log
3741       D:\Trial\codegenpath\ramcovm247_portal_765\EDKTypes.log
10644      D:\Trial\zippedpath\ramcovm247_portal_765\EDKPLAjaxCodeGen.log
11714      D:\Trial\zippedpath\ramcovm247_portal_765\EDKService.log
7482       D:\Trial\zippedpath\ramcovm247_portal_765\EDKTypes.log

但我需要像这样写一个接一个

5506       D:\Trial\codegenpath\ramcovm247_portal_765\EDKPLAjaxCodeGen.log
10644      D:\Trial\zippedpath\ramcovm247_portal_765\EDKPLAjaxCodeGen.log
5857       D:\Trial\codegenpath\ramcovm247_portal_765\EDKService.log
11714      D:\Trial\zippedpath\ramcovm247_portal_765\EDKService.log
3741       D:\Trial\codegenpath\ramcovm247_portal_765\EDKTypes.log
7482       D:\Trial\zippedpath\ramcovm247_portal_765\EDKTypes.log

这是我的代码

 var queryList1Only2 = (from file in list1 select file).Except(list2, myFileCompare1);
 var queryList1Only22 = (from file in list2 select file).Except(list1, myFileCompare1);
 var difference = queryList1Only2.ToHashSet();
 difference.SymmetricExceptWith(queryList1Only22);
 foreach (var v in difference )
       {
             dest.WriteLine(v.Length + "       " + v.FullName);

       }

public class FileCompareLength : System.Collections.Generic.IEqualityComparer<System.IO.FileInfo>
        {
            public FileCompareLength() { }
            public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
            {
                return (f1.Length == f2.Length);
            }
            public int GetHashCode(System.IO.FileInfo fi)
            {
                string s = String.Format("{0}", fi.Length);
                return s.GetHashCode();
            }
        }

有什么建议吗?

1 个答案:

答案 0 :(得分:1)