Prikazi cijelu temu 19.10.2015 14:20
Avko Van mreze
Administrator
Registrovan od:28.05.2014
Lokacija:zagreb


Predmet:usporedi dva fajla
Ova funkcija će usporediti jednu datoteke sa drugom. Moze usporediti samo duzinu datoteka ili razliku datoteka byte po byte.
Pozivate je:
usporediDatoteke(File1,File2) - samo za usporediti duzinu datoteka
usporediDatoteku(File1,File2,True) - usporeduje byte po byte datoteka

gdje su File1=App.Path & "/ime1.ext" i File2=App.Path & "/ime2.ext"

PreuzmiIzvorni kôd (Visual Basic):
  1. Function usporediDatoteke(ByVal File1 As String, _
  2.   ByVal File2 As String, Optional StringentCheck As _
  3.   Boolean = False) As Boolean
  4. '*******************************************************************************************
  5. 'Ime: usporediDatoteke
  6. 'Namjena: Provjeri dali su dvije datoteke identicne
  7. 'Autor: Ervin Kosch
  8. 'Ulazni parametri:
  9. '     -File1 i File2  = putanje sa imenom datoteke
  10. '     -StringentCheck = if false (default), usporeduje samo duzinu
  11. '     -StringentCheck = if true , usporeduje byte po byte datoteke
  12. 'Izlazni parametri: Boolean
  13. '********************************************************************************************
  14.  
  15. On Error GoTo ErrorHandler
  16.  
  17. If Dir(File1) = "" Then Exit Function
  18. If Dir(File2) = "" Then Exit Function
  19.  
  20. Dim lLen1 As Long, lLen2 As Long
  21. Dim iFileNum1 As Integer
  22. Dim iFileNum2 As Integer
  23. Dim bytArr1() As Byte, bytArr2() As Byte
  24. Dim lCtr As Long, lStart As Long
  25. Dim bAns As Boolean
  26.  
  27. lLen1 = FileLen(File1)
  28. lLen2 = FileLen(File2)
  29. If lLen1 <> lLen2 Then
  30.     Exit Function
  31. ElseIf StringentCheck = False Then
  32.         usporediDatoteke = True
  33.         Exit Function
  34. Else
  35.     iFileNum1 = FreeFile
  36.     Open File1 For Binary Access Read As #iFileNum1
  37.     iFileNum2 = FreeFile
  38.     Open File2 For Binary Access Read As #iFileNum2
  39.  
  40.     'put contents of both into byte Array
  41.    bytArr1() = InputB(LOF(iFileNum1), #iFileNum1)
  42.     bytArr2() = InputB(LOF(iFileNum2), #iFileNum2)
  43.     lLen1 = UBound(bytArr1)
  44.     lStart = LBound(bytArr1)
  45.    
  46.     bAns = True
  47.     For lCtr = lStart To lLen1
  48.         If bytArr1(lCtr) <> bytArr2(lCtr) Then
  49.             bAns = False
  50.             Exit For
  51.         End If
  52.            
  53.     Next
  54.     usporediDatoteke = bAns
  55.        
  56. End If
  57.  
  58. ErrorHandler:
  59. If iFileNum1 > 0 Then Close #iFileNum1
  60. If iFileNum2 > 0 Then Close #iFileNum2
  61. End Function

zivot je moja domovina.