@@ -42,8 +42,6 @@ def process_files():
42
42
duplicate_positions = set ()
43
43
near_duplicate_positions = set ()
44
44
45
- auto_select_dir = auto_select_entry .get ()
46
-
47
45
position_to_files , duplicate_positions , near_duplicate_positions , invalid_positions , filenames_within_group = find_duplicate_and_near_duplicate_positions (
48
46
directory ,
49
47
duplicates ,
@@ -55,10 +53,8 @@ def process_files():
55
53
round_positions = clean_options ['round_positions' ],
56
54
find_near_duplicates = duplicate_options ['find_similar_matches' ],
57
55
tolerance = duplicate_options ['similarity_threshold' ],
58
- progress_callback = lambda current , total , file_path : update_progress (current , total , file_path , duplicate_positions , near_duplicate_positions ),
59
- auto_select_dir = auto_select_dir
56
+ progress_callback = lambda current , total , file_path : update_progress (current , total , file_path , duplicate_positions , near_duplicate_positions )
60
57
)
61
-
62
58
end_time = time .time ()
63
59
64
60
progress_bar .stop ()
@@ -69,45 +65,6 @@ def process_files():
69
65
duplicate_window .geometry ("800x600" )
70
66
duplicate_window .resizable (True , True )
71
67
72
- def auto_select_files ():
73
- auto_select_dir = auto_select_entry .get ()
74
- if auto_select_dir :
75
- auto_select_pattern = os .path .join (auto_select_dir , '*' )
76
- auto_select_files = glob .glob (auto_select_pattern )
77
-
78
- selected_indices = []
79
- for index , result_file in enumerate (duplicate_listbox .get (0 , tk .END )):
80
- if result_file in auto_select_files :
81
- selected_indices .append (index )
82
-
83
- duplicate_listbox .selection_set (selected_indices )
84
-
85
- for rounded_position , file_paths in position_to_files .items ():
86
- selected_file = None
87
- for file_path in file_paths :
88
- if file_path not in filenames_within_group [rounded_position ]:
89
- filenames_within_group [rounded_position ].add (file_path )
90
- selected_file = file_path
91
- break
92
-
93
- if auto_select_dir and selected_file :
94
- auto_select_pattern = os .path .join (auto_select_dir , '*' )
95
- if selected_file .startswith (auto_select_pattern ):
96
- index = duplicate_listbox .get (0 , tk .END ).index (os .path .relpath (selected_file , directory ))
97
- duplicate_listbox .itemconfig (index , bg = 'lightblue' )
98
-
99
- auto_select_frame = tk .Frame (duplicate_window )
100
- auto_select_frame .pack (pady = 10 )
101
-
102
- auto_select_label = tk .Label (auto_select_frame , text = "Auto-Select Directory (with wildcards):" )
103
- auto_select_label .pack (side = tk .LEFT )
104
-
105
- auto_select_entry = tk .Entry (auto_select_frame , width = 30 )
106
- auto_select_entry .pack (side = tk .LEFT , padx = 5 )
107
-
108
- auto_select_button = tk .Button (auto_select_frame , text = "Auto-Select" , command = auto_select_files )
109
- auto_select_button .pack (side = tk .LEFT )
110
-
111
68
duplicate_frame = tk .Frame (duplicate_window )
112
69
duplicate_frame .pack (fill = tk .BOTH , expand = True , pady = 10 , padx = 10 )
113
70
@@ -130,6 +87,20 @@ def auto_select_files():
130
87
duplicate_listbox .insert (tk .END , os .path .relpath (file_path , directory ))
131
88
duplicate_listbox .insert (tk .END , "" ) # Add a blank line between groups
132
89
90
+ def auto_select_files (directory ):
91
+ auto_select_dir = auto_select_entry .get ()
92
+ if auto_select_dir :
93
+ selected_indices = []
94
+ for index , result_file in enumerate (duplicate_listbox .get (0 , tk .END )):
95
+ if result_file :
96
+ if result_file .startswith (auto_select_dir ):
97
+ selected_indices .append (index )
98
+
99
+ duplicate_listbox .selection_clear (0 , tk .END ) # Clear any previous selection
100
+ for index in selected_indices :
101
+ duplicate_listbox .selection_set (index )
102
+ duplicate_listbox .itemconfig (index , bg = 'lightblue' )
103
+
133
104
def delete_selected_files ():
134
105
selected_indices = duplicate_listbox .curselection ()
135
106
selected_files = [duplicate_listbox .get (index ) for index in selected_indices ]
@@ -183,11 +154,23 @@ def move_selected_files():
183
154
move_button = tk .Button (action_frame , text = "Move Selected Files" , command = move_selected_files )
184
155
move_button .pack (side = tk .LEFT )
185
156
157
+ auto_select_frame = tk .Frame (duplicate_window )
158
+ auto_select_frame .pack (pady = 10 )
159
+
160
+ auto_select_label = tk .Label (auto_select_frame , text = "Auto-Select Directory (with wildcards):" )
161
+ auto_select_label .pack (side = tk .LEFT )
162
+
163
+ auto_select_entry = tk .Entry (auto_select_frame , width = 30 )
164
+ auto_select_entry .pack (side = tk .LEFT , padx = 5 )
165
+
166
+ auto_select_button = tk .Button (auto_select_frame , text = "Select" , command = lambda : auto_select_files (directory ))
167
+ auto_select_button .pack (side = tk .LEFT )
168
+
186
169
def save_results ():
187
170
file_path = filedialog .asksaveasfilename (defaultextension = ".txt" , filetypes = [("Text Files" , "*.txt" ), ("All Files" , "*.*" )])
188
171
if file_path :
189
172
try :
190
- with open (file_path , "w" ) as file :
173
+ with open (file_path , "w" , encoding = "utf-8" ) as file :
191
174
file .write ("Exact Duplicate Positions:\n " )
192
175
for position in duplicate_positions :
193
176
file .write (f"Position: { position } \n " )
0 commit comments