Return false to indicate files are different Return true to indicate that the files are the same.įs1 = new FileStream(file1, FileMode.Open) įs2 = new FileStream(file2, FileMode.Open) Determine if the same file was referenced two times. Private bool FileCompare(string file1, string file2) A return value of any other value indicates that the A return value of 0 indicates that the contents of the files By default, Form1 is created.Īdd the following using statement to the Form1 class: using System.IO Īdd the following method to the Form1 class: // This method accepts two strings the represent two files to If the size of the two files is not the same, the two files are not the same.Ĭreate a new Visual C# Windows Application project.If both file references point to the same file, the two files must be equal.The code also performs two simple checks to increase the efficiency of the comparison: 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. 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. This comparison looks at the contents of the two files, not at the file names, locations, dates, times, or other attributes. This step-by-step article demonstrates how to compare two files to see if their contents are the same. NET Framework Class Library namespace System.IO. Original product version: Visual C# Original KB number: 320348 Summary This article provides information about how to create a File-Compare function in Visual C# and includes a code sample to explain the methods.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |