Compare two Folder Contents using c#
I need to compare two folder contents based on
1.No of files
2.Size of files
3 date
and i got an error index out of bound exception in this piece of code
private void SeekFiles(string Root)
{
string[] Files = System.IO.Directory.GetFiles(Root);
string[] Folders = System.IO.Directory.GetDirectories(Root)开发者_开发问答;
FileInfo File;
for(int i=0; i< Folders.Length; i++)
{
File = new FileInfo(Files[i]);
FolderSize += File.Length;
}
for(int i=0; i< Folders.Length-1; i++)
{
SeekFiles(Folders[i]);
}
}
Any Suggestion??
Looks like you are using wrong index on a wrong collection :
for(int i=0; i< Folders.Length; i++)
{
File = new FileInfo(Files[i]);
FolderSize += File.Length;
}
Should be :
for(int i=0; i< **Files.Length**; i++)
{
File = new FileInfo(Files[i]);
FolderSize += File.Length;
}
You are using Files[i] but i < Folders.Length in the first for.
for(int i=0; i< Folders.Length; i++)
{
File = new FileInfo(Files[i]);
FolderSize += File.Length;
}
This should be Files.Length
精彩评论