Hi,

I am trying to create an application that gets the contents of two folders. It should compare the file names in the two folders and put files with different names into a list (unique). Each file with the same name in both folders should be read and the contents compared. If the actual contents of the two text files are the same, the filename should be added to list fileSame, otherwise it should be placed into the fileDifferent list.

I can compare the filenames but I cannot figure out how to compare the actual contents of the two files. I have pasted the code from my button below, Please Help :)

if(path1->Text != "" || path2->Text != "")
{
		DirectoryInfo ^ dirInfo = gcnew DirectoryInfo(path1->Text);
		DirectoryInfo ^ dirInfo2 = gcnew DirectoryInfo(path2->Text);
			array< FileInfo ^ > ^ files = dirInfo->GetFiles();
 		        array< FileInfo ^ > ^ files2 = dirInfo2->GetFiles();					          
                        for( int i = 0; i < files->Length; i++)
			{
						String ^ currFileName = files[i]->ToString();
						bool result = false;
						for( int j = 0; j < files2->Length; j++)
						{
							String ^ currFileName2 = files2[j]->ToString();
							if(currFileName == currFileName2)
							{
								if(currFileName->Equals(currFileName2))
								{
									fileSame->Items->Add(files[i]);
									result = true;
								}
								else
								{
									fileDifferent->Items->Add(files[i]);
									result = true;
								}

							}	
			                        }
			if(result == false)
			{
				fileUnique->Items->Add(files[i]);
			}
}

Thanks,

Rob

After getting the two file names if they are the same open the two files with normal streams then read them one character at a time.

HI - thanks for your reply. I have been trying this using FileStream but am not sure on the correct syntax and keep getting errors. Do you know how to do what you suggested? Please use my variable names in your response if possible :)

Thanks

Rob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.