Question:
I’ve been trying to create a small program to compare two collections of strings and to output any items that are different or missing between collection1 and collection2.As far as I have been able to determine LINQ’s .Except method should provide my desired outcome but it seems to fall short.
The files which I’m trying to compare are the ACL files produced by using ICACLS to save all the permissions on a given directory and its subdirectories by running the following command from cmd:
Here is some sample code for trying to compare these items
First file:
An additional note is that this only seems to throw up issues with any of the permissions strings themselves, .Except does seem able to determine any missing strings when it’s one of the folder/file names, so I’m thinking it may be getting confused because there are many identical permissions strings within the collection so it may think it’s got a matching item even though it’s not got a specific record relating to a specific file.
I expect this will need some sort of custom override but I’m not sure what this implementation would be.
Any thoughts would be much appreciated, thanks for taking the time to read this through.
Answer:
I’m not sure if my assumptions are correct, but it looks like the format of the file generated is two lines per directory entry and that the first line is the full path to the file and hence must be unique.If that is correct, then the second list can not contain the line
TestHash\testFile3.csv
.If so then you can group the directory entry with the permission and then use except to check for differences.
To do this, I first add a line number to each line and then group by every two lines and the create an anonymous object with the first and second entries in each group,
eg
Or you could combine groupedList1 and groupedList2 like
If you have better answer, please add a comment about this, thank you!