C# 比较两个文件夹中对称性不同的不相同文件?
我正在比较两个文件夹中对称差异的不相同文件,并将长度和目录名写入一个文本文件…但它是这样写的C# 比较两个文件夹中对称性不同的不相同文件?,c#,linq,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\EDKTy
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);
}
及
公共类文件比较长度:System.Collections.Generic.IEqualityComparer
{
公共文件比较长度(){}
public bool等于(System.IO.FileInfo f1、System.IO.FileInfo f2)
{
返回值(f1.Length==f2.Length);
}
public int GetHashCode(System.IO.FileInfo-fi)
{
字符串s=string.Format(“{0}”,fi.Length);
返回s.GetHashCode();
}
}
有什么建议吗?试试这个试试这个@Bolu:它是在第一个路径中写入所有文件,然后在第二个路径中写入所有文件…我需要的是在第二个路径中写入一个文件,在第二个路径中写入比较文件这就是为什么我问:你能按你想要的顺序(按文件名)排序吗在你列出它之前…@Bolu:它在第一个路径中写入所有文件,然后在第二个路径中写入所有文件…我需要的是在第二个路径中写入一个文件,并在第二个路径中写入比较文件。这就是为什么我问你:在列出它之前,你能按你想要的顺序(按文件名)排序吗。。。
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();
}
}