It easy to find all file from a directory whether it is in a Directory or in sub directory by using string[] file = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); function. Now come on real problem how to compare to file two possible method first open file and read its byte and compare with other file’s bytes but it could be more long way I think So what I have done . I just use the string fi= File.ReadAllText(first); . Function and compare its text in if statement if the both text are equal it pass through the if and give the result file matched and if text are not same then returns files are not same.
Ex.
private bool filecheck(string first, string second )
{
string fi= File.ReadAllText(first);
string se= File.ReadAllText(second);
if (fi == se)
{
return true;
}
else
{
return false;
}
}
And you can make another function for result;
String array gvar[] is a global variable.
private void checkfun()
{
try
{ string[] file = Directory.GetFiles(textBox2.Text, "*.*", SearchOption.AllDirectories);
pro = file.Length;
foreach (string f1 in file)
{
proval++;
foreach (string f2 in file)
{
if (f1 != f2 && f1.Remove(0,f1.LastIndexOf('.')).ToLower()==f2.Remove(0,f2.LastIndexOf('.')).ToLower())
{
if (filecheck(f1, f2) )
{
gvar[i] =f1+ Environment.NewLine + f2 + Environment.NewLine + "------------------------------------------------" + Environment.NewLine;
i++;
}
}
}
}
}
catch {
}
MessageBox.Show("All Result Has Shown!");
}
No comments:
Post a Comment