compare two folders for non identical files with SymmetricDifference?

前端 未结 1 1619
离开以前
离开以前 2020-12-22 07:21

I have two folders A and B..inside that two folders lots of folders and files are there... I am comparing these two folders for non identical files with symmetric difference

1条回答
  •  一整个雨季
    2020-12-22 07:43

    It feels to me like you're looking for different things, really:

    • Files which are present in one directory but not the other (so use symmetric difference)

    • Files where they are present in both directories, but then:

      • Those which differ by length
      • Those which differ by last write time

    I would treat these separately. You already know how to do the first part. To get the second part, you need the intersection of the two sets of filenames (just use the Intersect extension method). From that you can list differences:

    var differentLengths = from name in intersection
                           let file1 = new FileInfo(directory1, name)
                           let file2 = new FileInfo(directory2, name)
                           where file1.Length != file2.Length
                           select new { Name = name,
                                        Length1 = file1.Length,
                                        Length2 = file2.Length };
    

    ... you can then print those out. You can then do the same for last write times.

    In other words, you don't actually need a comparer which compares all of the properties at a time.

    0 讨论(0)
提交回复
热议问题