-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind_duplicates_in_two_folder.py
More file actions
38 lines (30 loc) · 1.25 KB
/
find_duplicates_in_two_folder.py
File metadata and controls
38 lines (30 loc) · 1.25 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
import os
import pathlib
def scan_folders(folder_A, folder_B):
files_A = set()
files_B = set()
for dirpath, dirnames, filenames in os.walk(folder_A):
for f in filenames:
full_path = pathlib.Path(dirpath) / f
files_A.add((f, full_path))
for dirpath, dirnames, filenames in os.walk(folder_B):
for f in filenames:
full_path = pathlib.Path(dirpath) / f
files_B.add((f, full_path))
with open('all_files_with_full_path.txt', 'w', encoding='utf-8') as f:
all_files = sorted(list(files_A | files_B))
for filename, full_path in all_files:
f.write(f'{full_path}\n')
with open('all_files_only_name.txt', 'w', encoding='utf-8') as f:
all_file_names = sorted(list(set(item[0] for item in files_A | files_B)))
for filename in all_file_names:
f.write(f'{filename}\n')
duplicate_files = files_A & files_B
with open('duplicate_files.txt', 'w', encoding='utf-8') as f:
sorted_duplicates = sorted(list(duplicate_files))
for filename, full_path in sorted_duplicates:
f.write(f'{full_path}\n')
folder_A = r'E:\BackupD'
folder_B = r'F:\New-2024-aug'
scan_folders(folder_A, folder_B)
print("Output files created.")