Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 比较两个文件夹中对称性不同的不相同文件?_C#_Linq - Fatal编程技术网

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