2010-12-13 26 views
1

Je compare deux dossiers pour les fichiers non identiques à la différence symétrique et écrire la longueur et le nom du répertoire dans un fichier texte ... Mais il est en train d'écrire commecomparez deux dossiers pour des fichiers non identiques avec 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 

mais je dois écrire un après l'autre comme celui-ci

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 

Voici mon code

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); 

     } 

et

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(); 
      } 
     } 

Une suggestion?

+0

pouvez-vous TRIER 'difference'? – Bolu

+0

@Bolu: Il écrit tous les fichiers dans le premier chemin, puis tous les fichiers dans le second chemin ... ce dont j'ai besoin est d'écrire un fichier dans le chemin et le fichier comparatif dans le second chemin – bala3569

+0

Voilà pourquoi je demande: pouvez-vous le trier dans l'ordre que vous voulez (par nom de fichier) avant de le lister ... – Bolu

Répondre