I've just started C# and have little experience with programming. I've browsed trhough many topics in this forum but none seem to be exactly what I'm looking for...
I want to create a tool which compares to files, not in bytesize but in by content. I've managed to create a tool who does so, but he compares complete files. I'm unable to create a way the tool stops when a certain phrase comes up. So I had the idea to create two temporary files which I compare, but here I have the same problem. I'm unable to copy a certain block of data.
Is there anybody who can help me with my problem?
Copy and Edit Data in File
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Jan 14, 2008, 11:13 AM EST
private bool AreFilesEqual(string filePathOne, string filePathTwo)
{
StreamReader fileOneReader = new StreamReader(new FileStream(filePathOne, FileMode.Open));
StreamReader fileTwoReader = new StreamReader(new FileStream(filePathTwo, FileMode.Open));
if(fileOneReader.ReadToEnd() != fileTwoReader.ReadToEnd())
return false;
else
return true;
}
Im not quite sure though what you are trying to copy. Do you want to copy the line of data that is in one file and not the other to the file that is missing it?
Dennis3 pointsPosted Jan 14, 2008, 10:12 PM EST
private bool AreFilesEqual(string filePathOne, string filePathTwo)
{
StreamReader fileOneReader = new StreamReader(new FileStream(filePathOne, FileMode.Open));
StreamReader fileTwoReader = new StreamReader(new FileStream(filePathTwo, FileMode.Open));
if(fileOneReader.ReadToEnd() != fileTwoReader.ReadToEnd())
return false;
else
return true;
}
Because of the ReadToEnd() it compares the complete file. This is not what I want.