diff --git a/1ano/fp/aula06/comparefiles.py b/1ano/fp/aula06/comparefiles.py new file mode 100644 index 0000000..5ed2088 --- /dev/null +++ b/1ano/fp/aula06/comparefiles.py @@ -0,0 +1,29 @@ +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()