I develop a little software which permits me to compare 2 folders and Add files.
I take principally code from msdn.
That looks to work fine with some files but I have some troubles with 2 folders (292 and 268 files).
In my case with the 2 big folder I have thoses differences found by the method :
C:\Users\Puppie\Desktop\KittiesWarWP8\KittiesWarWP8.sdf
C:\Users\Puppie\Desktop\KittiesWarWP8\Debug\KWGameComp\KWGameComp.pdb
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGame\Bin\x86\Debug\KWGame_Debug_x86.xap
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGame\obj\x86\Debug\KWGame.csprojResolveAssemblyReference.cache
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGame\obj\x86\Debug\XapCacheFile.xml
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGameComp\Debug\fxc.write.1.tlog
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGameComp\Debug\KWGameComp.write.1.tlog
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGame\KWGameComp\Debug\link.write.1.tlog
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Thumbs.db
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\Thumbs.db
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\obj\x86\Debug\KWGamePages.csprojResolveAssemblyReference.cache
But I have see that miss some files 292 - 268 = 24 files. The method found me only 11 ... . I check and find a little folder which one looks like to be ignored from the method :
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\AlignmentGrid.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\ApplicationIcon.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\FlipCycleTileLarge.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\FlipCycleTileMedium.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\FlipCycleTileSmall.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\IconicTileMediumLarge.png
C:\Users\Puppie\Desktop\KittiesWarWP8\KWGamePages\Assets\Tiles\IconicTileSmall.png
Thoses files are totally ignored.. I have made 2 folder for test just thoses files (folder 1 and 2) and the result for the difference by the same method is :
C:\Users\Puppie\Desktop\1\Assets\AlignmentGrid.png
C:\Users\Puppie\Desktop\1\Assets\ApplicationIcon.png
C:\Users\Puppie\Desktop\1\Assets\Tiles\FlipCycleTileLarge.png
C:\Users\Puppie\Desktop\1\Assets\Tiles\FlipCycleTileMedium.png
C:\Users\Puppie\Desktop\1\Assets\Tiles\FlipCycleTileSmall.png
C:\Users\Puppie\Desktop\1\Assets\Tiles\IconicTileMediumLarge.png
C:\Users\Puppie\Desktop\1\Assets\Tiles\IconicTileSmall.png
Tada when the folder is small he found the difference perfectly, in the destination folder for the test 1 and the destination folder for the test 2 thoses pictures do not exist ( I have checked).
So i just want to know if the method on msdn have a limit ?
There is the real source code : http://msdn.microsoft.com/en-us/library/bb546137.aspx
and mine just a little modified (add Directories) :
compare method :
path A : C:\Users\Puppie\Desktop\KittiesWarWP8\
path B : C:\Users\Puppie\Desktop\Logiciel pour projet\KittiesWarWP8\
private void checkFiles()
{
List<string> dir = new List<string>();
int lenghtPath = pathA.Length - (new DirectoryInfo(pathA).Name).Length - 1;
System.IO.DirectoryInfo dir1 = new System.IO.DirectoryInfo(pathA);
System.IO.DirectoryInfo dir2 = new System.IO.DirectoryInfo(pathB);
// Take a snapshot of the file system.
IEnumerable<System.IO.FileInfo> list1 = dir1.GetFiles("*", System.IO.SearchOption.AllDirectories);
IEnumerable<System.IO.FileInfo> list2 = dir2.GetFiles("*", System.IO.SearchOption.AllDirectories);
//A custom file comparer defined below
FileCompare myFileCompare = new FileCompare();
// Find the set difference between the two folders.
// For this example we only check one way.
var queryList1Only = (from file in list1 select file).Except(list2, myFileCompare);
int temp;
foreach (var v in queryList1Only)
{
if (dir.Count == 0)
{
if (!new FileInfo(pathB + (v.FullName.Remove(0, pathA.Length))).Exists)
{
//we do a little verification
//the software must do not take the base folder
if (!(new FileInfo(v.FullName).DirectoryName + @"\").Equals(pathA))
{
dir.Add(new FileInfo(v.FullName).DirectoryName);
this.checkedListBox1.Items.Add("INEXISTANT | " + dir[dir.Count - 1]);
}
this.checkedListBox1.Items.Add("INEXISTANT | " + v.FullName);
}
else
{
//we do a little verification
//the software must do not take the base folder
if (!(new FileInfo(v.FullName).DirectoryName + @"\").Equals(pathA))
{
dir.Add(new FileInfo(v.FullName).DirectoryName);
this.checkedListBox1.Items.Add("MODIFIE | " + dir[dir.Count - 1]);
}
this.checkedListBox1.Items.Add("MODIFIE | " + v.FullName);
}
}
else
{
bool find = false;
int save = 0;
for (int i = 0; i < dir.Count; i++)
{
if ((new FileInfo(v.FullName).DirectoryName).Equals(dir[i]))
{
find = true;
save = i;
i = dir.Count;
}
}
if (!find)
{
if (!new FileInfo(pathB + (v.FullName.Remove(0, pathA.Length))).Exists)
{
dir.Add(new FileInfo(v.FullName).DirectoryName);
this.checkedListBox1.Items.Add("INEXISTANT | " + dir[dir.Count - 1]);
this.checkedListBox1.Items.Add("INEXISTANT | " + v.FullName);
}
else
{
dir.Add(new FileInfo(v.FullName).DirectoryName);
this.checkedListBox1.Items.Add("MODIFIE | " + dir[dir.Count - 1]);
this.checkedListBox1.Items.Add("MODIFIE | " + v.FullName);
}
}
else
{
if (!new FileInfo(pathB + (v.FullName.Remove(0, pathA.Length))).Exists)
this.checkedListBox1.Items.Add("INEXISTANT | " + v.FullName);
else
this.checkedListBox1.Items.Add("MODIFIE | " + v.FullName);
}
}
}
}
compare Class :
class FileCompare : System.Collections.Generic.IEqualityComparer<System.IO.FileInfo>
{
public FileCompare() { }
public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
{
return (f1.Name == f2.Name &&
f1.Length == f2.Length);
}
// Return a hash that reflects the comparison criteria. According to the
// rules for IEqualityComparer<T>, if Equals is true, then the hash codes must
// also be equal. Because equality as defined here is a simple value equality, not
// reference identity, it is possible that two or more objects will produce the same
// hash code.
public int GetHashCode(System.IO.FileInfo fi)
{
string s = String.Format("{0}{1}", fi.Name, fi.Length);
return s.GetHashCode();
}
}
thanks in advance for your help ;).
PS : sorry for my medium english