1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
namespace Compare
{
public partial class Form1 : Form
{
public ArrayList PasDans1 = new ArrayList();
public ArrayList PasDans2 = new ArrayList();
public ArrayList Differents = new ArrayList();
public ArrayList Identiques = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox3.Text = "";
DirectoryInfo Folder1, Folder2;
try { Folder1 = new DirectoryInfo(textBox1.Text); }
catch
{
MessageBox.Show("Chemin 1 incorrect !", "ATTENTION !", MessageBoxButtons.OK);
goto end;
}
try { Folder2 = new DirectoryInfo(textBox2.Text); }
catch
{
MessageBox.Show("Chemin 2 incorrect !", "ATTENTION !",MessageBoxButtons.OK);
goto end;
}
FileInfo[] MyFileInfoList1 = Folder1.GetFiles();
FileInfo[] MyFileInfoList2 = Folder2.GetFiles();
foreach (FileInfo MyFileInfo in MyFileInfoList1)
{
if (Contains(MyFileInfoList2, MyFileInfo))
{
if (Read(textBox1.Text + "\\" + MyFileInfo.Name) != Read(textBox2.Text + "\\" + MyFileInfo.Name))
Differents.Add(MyFileInfo.Name);
else
Identiques.Add(MyFileInfo.Name);
}
else
{
PasDans2.Add(MyFileInfo.Name);
}
}
foreach (FileInfo MyFileInfo in MyFileInfoList2)
{
if (!Contains(MyFileInfoList1, MyFileInfo))
PasDans1.Add(MyFileInfo.Name);
}
string[] notin1 = new string[PasDans1.Count];
PasDans1.CopyTo(notin1);
string[] notin2 = new string[PasDans2.Count];
PasDans2.CopyTo(notin2);
string[] diff = new string[Differents.Count];
Differents.CopyTo(diff);
string[] id = new string[Identiques.Count];
Identiques.CopyTo(id);
textBox3.Text = "Fichiers non présents dans le dossier 1 :\r\n" +
System.String.Join("\r\n", notin1) + "\r\n\r\n" +
"Fichiers non présents dans le dossier 2 :\r\n" +
System.String.Join("\r\n", notin2) + "\r\n\r\n" +
"Fichiers différents :\r\n" +
System.String.Join("\r\n", diff) + "\r\n\r\n" +
"Fichiers Identiques :\r\n" +
System.String.Join("\r\n", id);
end: ;
}
private bool Contains(FileInfo[] List, FileInfo Elmt)
{
foreach (FileInfo MyFileInfo in List)
{
if (MyFileInfo.Name == Elmt.Name)
{
return true;
}
}
return false;
}
private string Read(string FileToRead)
{
FileStream OrigFile = new FileStream(FileToRead, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(OrigFile, System.Text.Encoding.Default);
string s = sr.ReadToEnd();
sr.Close();
OrigFile.Close();
return (s);
}
}
} |
Partager