uaveiro-leci/1ano/fp/aula06/comparefiles.py

30 lines
652 B
Python
Raw Normal View History

2022-11-07 17:21:08 +00:00
from sys import argv
def main():
if len(argv) != 3:
file1 = input('File 1: ')
file2 = input('File 2: ')
else:
file1, file2 = argv[1:]
if compareFiles(file1, file2):
print('Os ficheiros são iguais!')
else:
print('Os ficheiros são diferentes!')
def compareFiles(file1, file2):
with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
while True:
data1 = f1.read(1024)
data2 = f2.read(1024)
if data1 != data2:
return False
if not data1 or not data2:
return True
if __name__ == "__main__":
main()