-
Notifications
You must be signed in to change notification settings - Fork 1
/
comperfiles.py
62 lines (49 loc) · 1.77 KB
/
comperfiles.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
while True:
name = input("Enter the name of the file (example: text.txt | D:/folder_nme/filename.txt) >> ")
name2 = input("Enter the name of the second file (example: text.txt | D:/folder_nme/filename.txt) >> ")
ty = input("Are the files text? Y/N >> ")
ty = ty.lower()
if name2 != "" and name != "" and ty != "":
break
if name == name2:
print("The names of the files are equal")
try:
if ty == "yes" or ty == "y":
file = open(name, "rt")
file2 = open(name2, "rt")
else:
file = open(name, "rb")
file2 = open(name2, "rb")
except Exception:
print("Check if the file exists and check if the file is in the right format. An exception was raised.")
exit()
lines = []
lines2 = []
for line in file:
if "\n" in line:
line = line.replace("\n", "")
lines.append(line)
for line4 in file2:
if "\n" in line4:
line4 = line4.replace("\n", "")
lines2.append(line4)
print("")
file1Size = len(lines)
file2Size = len(lines2)
if file1Size != file2Size or lines != lines2:
print("!< - > Different < - >!")
if file1Size != file2Size:
print(name + " have " + str(file1Size) + " lines")
print(name2 + " have " + str(file2Size) + " lines")
print("")
if lines != lines2:
justLines = []
for lineInFile in lines:
if lineInFile not in lines2:
justLines.append(lineInFile)
print(name + " -> " + lineInFile + " is not in " + name2)
for lineInFile2 in lines2:
if lineInFile2 not in lines and lineInFile2 not in justLines:
print(name2 + " -> " + lineInFile2 + " is not in " + name)
else:
print("< + > Equal < + > :)")