11-12-2024, 02:39 AM
Code: (Select All)
_Title"File Compare Tool"
' Keys...
' If the files are identical, it will instantly inform you.
' If the files are different, it will display both codes, line by line and pause with a "No Match!" alert were the code is different.
' When paused you can...
' F1 Copy to the clipboard the no match line (last line shown) of the 1st file.
' F2 Copy to the clipboard the no match line (last line shown) of the 2nd file.
' Note: Copy the line and paste it into an IDE search to find the code in your program.
' 1 Scroll to the next line of the 1st file.
' 2 Scroll to the next line of the 2nd file.
' Spacebar Toggle to pause/resume code while it is scrolling.
' Enter Auto continue (scroll both) to the next no match.
' Esc Quit
Width 150, 41
_Font 16
_ScreenMove 20, 0
v1top = 2: v1btm = 20
v2top = 22: v2btm = 40
View Print
Cls
target1$ = _OpenFileDialog$("Select First File to Compare", "", "*.*", "", 0)
target2$ = _OpenFileDialog$("Select Second File to Compare", "", "*.*", "", 0)
dir1$ = Mid$(target1$, 1, _InStrRev(target1$, "\"))
file1$ = Mid$(target1$, _InStrRev(target1$, "\") + 1)
dir2$ = Mid$(target2$, 1, _InStrRev(target2$, "\"))
file2$ = Mid$(target2$, _InStrRev(target2$, "\") + 1)
If dir1$ + file1$ = dir2$ + file2$ Then
Beep
Print: Print " Error: Both directory and file names are the same. Cannot compare the same file. Any key to redo": Sleep
If InKey$ = Chr$(27) Then System Else Run
End If
_Delay 1
start:
Cls
Locate 1, 1: Color 15, 1: Print Space$(_Width);
Locate 21, 1: Print Space$(_Width);
Locate 1, 2: Color 15, 1: Print dir1$;: Color 14, 1: Print file1$;
Locate 21, 2: Color 15, 1: Print dir2$;: Color 14, 1: Print file2$;
Color 7, 0
ReDim c1$(20000), c2$(20000): c1 = 0: p1 = 0: c2 = 0: p2 = 0
' Quick compare...
If Not _FileExists(dir1$ + file1$) Then
Print: Print: Print " Cannot find file: " + dir1$ + file1$ + ". Any key to retry.": _Delay 1: Sleep
End If
If Not _FileExists(dir2$ + file2$) Then
Print: Print: Print " Cannot find file: " + dir2$ + file2$ + ". Any key to retry.": _Delay 1: Sleep
End If
Open dir1$ + file1$ For Binary As #1
Open dir2$ + file2$ For Binary As #2
x1$ = Space$(LOF(1))
x2$ = Space$(LOF(2))
Get #1, , x1$
Get #2, , x2$
Close #1, 2
If x1$ = x2$ Then
Locate 41, 2: Print "Both files are identical. Press Enter to rerun or Esc to quit...";
Do
_Limit 30
b$ = InKey$
If Len(b$) Then
Select Case b$
Case Chr$(27)
System
Case Chr$(13): Cls: _Delay 1: Run
End Select
End If
Loop
End If
Open dir1$ + file1$ For Input As #1
Open dir2$ + file2$ For Input As #2
Do Until EOF(1)
Line Input #1, a$
a$ = RTrim$(LTrim$(a$))
If Mid$(a$, 1, 1) > " " Then
c1 = c1 + 1
c1$(c1) = a$
End If
Loop
Close #1
Do Until EOF(2)
Line Input #2, a$
a$ = RTrim$(LTrim$(a$))
If Mid$(a$, 1, 1) > " " Then
c2 = c2 + 1
c2$(c2) = a$
End If
Loop
Close #2
Locate 2, 1
onscr1$ = c1$(1)
onscr2$ = c1$(1)
yy1 = v1top: yy2 = v2top
p1 = 0: p2 = 0: auto = -1
Do
_Limit 300 ' Controls speed of screen display.
If auto = -1 And b$ <> Chr$(13) Then
If onscr1$ <> onscr2$ Then
Locate 41, 2
Color 14, 0
Print "No Match! ";
auto = 0
Color 7, 0
End If
End If
If auto Then
p$ = InKey$
Select Case p$
Case Chr$(27): System
Case Chr$(32)
y = CsrLin: x = Pos(0): Locate 41, 2: Color 14, 0: Print " Paused...";: Color 7, 0
Do: _Limit 30: p$ = InKey$: Loop Until p$ = Chr$(32)
Locate 41, 2: Print " ";
Locate y, x
Case "r", "R"
View Print: Run
Case Chr$(8), "V", "v"
View Print: GoTo start
End Select
If auto < 0 Then b$ = "1": auto = 1 Else b$ = "2": auto = -1
Else
b$ = InKey$
End If
If Len(b$) Then
Select Case b$
Case Chr$(27): System
Case "r", "R": View Print: Run
Case "v", "V", Chr$(8): View Print: GoTo start
Case Chr$(0) + Chr$(59): _Clipboard$ = c1$(p1)
Case Chr$(0) + Chr$(60): _Clipboard$ = c2$(p2)
Case Chr$(13), Chr$(0) + "P": b$ = Chr$(13): auto = -1: Locate 41, 2, 1, 7, 0: Print " ";
Case "1", "2"
Locate 41, 2, 1, 7, 0: Print " ";
If b$ = "1" And Len(c1$(p1 + 1)) Then
View Print v1top To v1btm
p1 = p1 + 1
Locate yy1, 1: Print p1; c1$(p1): yy1 = CsrLin
onscr1$ = c1$(p1)
End If
If b$ = "2" And Len(c2$(p2 + 1)) Then
View Print v2top To v2btm
p2 = p2 + 1
Locate yy2, 1: Print p2; c2$(p2): yy2 = CsrLin
onscr2$ = c2$(p2)
End If
End Select
End If
If p1 = c1 And p2 = c2 Then Exit Do
Loop
Close
Locate _Height, 2: Color 14, 0: Print "Finished. [R]un [V]iew Again [Q]uit: ";
Color 7, 0
Do
_Limit 30
b$ = InKey$
If Len(b$) Then
If UCase$(b$) = "Q" Or b$ = Chr$(27) Then System
If UCase$(b$) = "R" Then View Print: Cls: Run
If UCase$(b$) = "V" Or b$ = Chr$(8) Then View Print: GoTo start
End If
Loop
System
Much appreciation to the QB64 Dev Team for the _OpenFileDialog statement. It chopped my code required in half!
Here is a screen shot:
Pete
Shoot first and shoot people who ask questions, later.