السلام عليكم
أبحث عن كود للمقارنة بين ملفين نصيين بحيث يتم وضع كل سطر من الملف في مصفوفة
ومن ثم مقارنة المصفوفتين وبعدها الانتقال إلى السطر التالي إلى نهاية الملف
ما هو الغرض من ذلك لمعرفة ان الملفين مختلفين ام لماذا حيث ممكن تستخدمي اومر batch_script وبالخص الامر comp
This batch command compares 2 files based on the file size
Syntax
كود :
COMP [sourceA] [sourceB]
(02-04-18, 02:03 PM)محمود بكرى كتب : [ -> ]ما هو الغرض من ذلك لمعرفة ان الملفين مختلفين ام لماذا حيث ممكن تستخدمي اومر batch_script وبالخص الامر comp
This batch command compares 2 files based on the file size
Syntax
كود :
COMP [sourceA] [sourceB]
مقارنة السطر الاول من الملف الاول بالسطر الاول في الملف التاني وهكذا
فيه أكثر من أسلوب للمقارنة
مثلا تقوم بقراءة الملفات و تحول كل منهما الي مصفوفة بايت ثم تقارن بين المصفوفات
حل أخر تقرأ الملفات و تحول كل ملف الي مصفوفة سطور ثم تقارت المصفوفات ايضا
في كلتا الحالات فكرة كتابة الكود واحدة
الحل الأول
PHP كود :
Dim firstFile As String = ".\File1.txt"
Dim secondFile As String = ".\File2.txt"
Dim a As Byte() = IO.File.ReadAllBytes(firstFile)
Dim b As Byte() = IO.File.ReadAllBytes(secondFile)
Dim result As Boolean = False
If a Is Nothing AndAlso b Is Nothing Then
result = True
ElseIf a IsNot Nothing AndAlso b IsNot Nothing AndAlso a.Length = b.Length Then
result = True
For i As Integer = 0 To a.Length - 1
If a(i) <> b(i) Then
result = False
Exit For
End If
Next
End If
حل أخر
PHP كود :
Dim firstFile As String = ".\File1.txt"
Dim secondFile As String = ".\File2.txt"
Dim c As String() = IO.File.ReadAllLines(firstFile)
Dim d As String() = IO.File.ReadAllLines(secondFile)
Dim result As Boolean = False
If c Is Nothing AndAlso d Is Nothing Then
result = True
ElseIf c IsNot Nothing AndAlso d IsNot Nothing AndAlso c.Length = d.Length Then
result = True
For i As Integer = 0 To c.Length - 1
If c(i) <> d(i) Then
result = False
Exit For
End If
Next
End If