2010-12-13 103 views
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(); 
      } 
     } 

任何建議?

+0

你能分類'差異嗎? – Bolu 2010-12-13 09:36:41

+0

@Bolu:它是在第一個路徑中寫入所有文件,然後是第二個路徑中的所有文件......我需要的是在第二個路徑中寫入路徑和比較文件中的文件 – bala3569 2010-12-13 09:45:36

+0

這就是爲什麼我問:你能排序它在列出之前按您想要的順序(按文件名)... – Bolu 2010-12-13 09:47:53

回答