您的位置:首页 > 其它

比较两个文件夹内同名文件内容是否相同

2014-08-26 10:13 656 查看

string sourcePathA = @"patha"  

string sourcePathB = @"pathb";  

string[] filenames = Directory.GetFiles(sourceParhA) ; 

string[] directories = Directory.GetDirectories(sourcePathA);  

foreach(string file in fileNames)

{

     string useName = file.Substring(fie.LastIndexOf('\\')+1);

     string comparefile = sourcePathB + "\\" + useName;

     if(File.Exists(comparefile))

    {

         FileStream fsa = new FIlesStream(file,FileMode.Open,FIleAccess.Read);

         StreamReader sra = new StreamReader(fsa,Encoding.Default);

         string linea = sra.ReadToEnd();

         sra.Close();

         fsa.Close();

         FileStream fsb = new FIlesStream(comparefile,FileMode.Open,FIleAccess.Read);

         StreamReader srb = new StreamReader(fsb,Encoding.Default);

         string lineb = srb.ReadToEnd();

         sra.Close();

         fsa.Close();

         if(linea != lineb)

        {

                 return ;

        }

    }

}

 foreach (string dir in directories);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: