Added comparefiles.py

This commit is contained in:
tiagorg 2022-11-07 17:21:08 +00:00
parent 6cd9101be0
commit 372fa87c55
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 29 additions and 0 deletions

View File

@ -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()