How to create a File-Compare function in Visual C#

 

This article is from Microsoft Support. The orignal article is on http://support.microsoft.com/kb/320348.

 

This step-by-step article demonstrates how to compare two files to see if their contents are the same. This comparison looks at the contents of the two files, not at the file names, locations, dates, times, or other attributes.

This functionality is similar to the MS-DOS-based Fc.exe utility that is included with various versions of Microsoft Windows and Microsoft MS-DOS, and with some development tools.

The sample code that is described in this article performs a byte-by-byte comparison until it finds a mismatch or it reaches the end of the file. The code also performs two simple checks to increase the efficiency of the comparison:

  • If both file references point to the same file, the two files must be equal.
  • If the size of the two files is not the same, the two files are not the same.

To Create the Sample

  1. Create a new Visual C# Windows Application project. By default, Form1 is created.
  2. Add two textbox controls to the form.
  3. Add a command button to the form.
  4. On the View menu, click Code .
  5. Add the following USING statement to the Form1 class:
  6. Add the following method to the Form1 class:
  7. Paste the following code in the Click event of the command button:
  8. Save and then run the sample.
  9. Supply the full paths to the two files in the textboxes, and then click the command button.

For more information, visit the following Microsoft Web sites:

File Access Through the FileStream Class
( http://msdn2.microsoft.com/en-us/library/Aa903246(VS.71).aspx )
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值