-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_folder_diff.py
More file actions
48 lines (41 loc) · 1.4 KB
/
binary_folder_diff.py
File metadata and controls
48 lines (41 loc) · 1.4 KB
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
import os
import pathlib
from filecmp import cmp, clear_cache
folder_1 = "/users/skutluk/desktop/folder 1"
folder_2 = "/users/skutluk/desktop/folder 2"
files_1 = set()
files_2 = set()
diff = []
for root, dirs, files in os.walk(folder_1):
for file in files:
file_path = os.path.join(root, file)
p = file_path.removeprefix(folder_1 + "/")
if p not in files_1:
files_1.add(p)
else:
print("ITEM NOT UNIQUE!")
for root, dirs, files in os.walk(folder_2):
for file in files:
file_path = os.path.join(root, file)
p = file_path.removeprefix(folder_2 + "/")
if p not in files_2:
files_2.add(p)
else:
print("ITEM NOT UNIQUE!")
for file in files_1.copy():
if file in files_2:
clear_cache()
check = cmp(os.path.join(folder_1, file), os.path.join(folder_2, file), shallow=False)
if check is True:
files_1.remove(file)
files_2.remove(file)
else:
diff.append("Files are different: " + os.path.join(folder_1, file) + " and " + os.path.join(folder_2, file))
else:
diff.append(("Only in " + folder_1 + ": " + os.path.join(folder_1, file)))
for file in files_2:
if file in files_1:
print("SOMETHING WEIRD HAPPENED")
else:
diff.append(("Only in " + folder_2 + ": " + os.path.join(folder_2, file)))
print(*diff, sep = "\n")