1
我比较非完全相同的文件,两个文件夹具有对称差,写的长度和目录名到一个文本文件...但它是写像比较两个文件夹与SymmetricDifference非相同的文件?
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();
}
}
任何建议?
你能分类'差异吗? – Bolu 2010-12-13 09:36:41
@Bolu:它是在第一个路径中写入所有文件,然后是第二个路径中的所有文件......我需要的是在第二个路径中写入路径和比较文件中的文件 – bala3569 2010-12-13 09:45:36
这就是为什么我问:你能排序它在列出之前按您想要的顺序(按文件名)... – Bolu 2010-12-13 09:47:53