forked from PySimpleGUI/PySimpleGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo_Compare_Files.py
33 lines (27 loc) · 1.06 KB
/
Demo_Compare_Files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import PySimpleGUI as sg
def GetFilesToCompare():
with sg.FlexForm('File Compare') as form:
form_rows = [[sg.Text('Enter 2 files to comare')],
[sg.Text('File 1', size=(15, 1)), sg.InputText(), sg.FileBrowse()],
[sg.Text('File 2', size=(15, 1)), sg.InputText(), sg.FileBrowse()],
[sg.Submit(), sg.Cancel()]]
rc = form.LayoutAndShow(form_rows)
return rc
def main():
button, (f1, f2) = GetFilesToCompare()
if any((button != 'Submit', f1 =='', f2 == '')):
sg.MsgBoxError('Operation cancelled')
exit(69)
with open(f1, 'rb') as file1:
with open(f2, 'rb') as file2:
a = file1.read()
b = file2.read()
for i, x in enumerate(a):
if x != b[i]:
sg.MsgBox('Compare results for files', f1, f2, '**** Mismatch at offset {} ****'.format(i))
break
else:
if len(a) == len(b):
sg.MsgBox('**** The files are IDENTICAL ****')
if __name__ == '__main__':
main()