mirror of
https://github.com/kevinveenbirkenbach/duplicate-file-handler.git
synced 2024-12-22 19:25:04 +01:00
Optimized show logic
This commit is contained in:
parent
f854e46511
commit
9e815c6854
34
create_file_structure.py
Normal file
34
create_file_structure.py
Normal file
@ -0,0 +1,34 @@
|
||||
import os
|
||||
import shutil
|
||||
import hashlib
|
||||
import random
|
||||
import string
|
||||
|
||||
def create_test_directory(base_dir, num_files=5, duplicate_files=2, depth=1):
|
||||
os.makedirs(base_dir, exist_ok=True)
|
||||
subdirs = [os.path.join(base_dir, f"subdir_{i}") for i in range(depth)]
|
||||
for subdir in subdirs:
|
||||
os.makedirs(subdir, exist_ok=True)
|
||||
|
||||
for dir in [base_dir] + subdirs:
|
||||
file_names = [f"file_{i}.txt" for i in range(num_files)]
|
||||
for file_name in file_names:
|
||||
with open(os.path.join(dir, file_name), 'w') as f:
|
||||
content = ''.join(random.choices(string.ascii_lowercase, k=20))
|
||||
f.write(content)
|
||||
|
||||
for i in range(min(duplicate_files, num_files)):
|
||||
original = os.path.join(dir, file_names[i])
|
||||
for dup_num in range(1, duplicate_files+1):
|
||||
duplicate = os.path.join(dir, f"dup_{dup_num}_{file_names[i]}")
|
||||
shutil.copyfile(original, duplicate)
|
||||
|
||||
def create_file_structure(depth, num_files, duplicate_files):
|
||||
base_dirs = ['test_dir1', 'test_dir2']
|
||||
for base_dir in base_dirs:
|
||||
create_test_directory(base_dir, num_files, duplicate_files, depth)
|
||||
|
||||
print("Test file structure created.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
create_file_structure(depth=2, num_files=5, duplicate_files=3)
|
4
main.py
4
main.py
@ -42,7 +42,7 @@ def handle_modification(files, modification, mode, apply_to):
|
||||
for duplicate_file in files:
|
||||
if duplicate_file != original_file:
|
||||
if duplicate_file.startswith(tuple(apply_to)):
|
||||
if mode == 'preview':
|
||||
if mode == 'preview' and modification != 'show':
|
||||
print(f"Would perform {modification} on {duplicate_file}")
|
||||
elif mode == 'act':
|
||||
handle_file_modification(original_file, duplicate_file, modification)
|
||||
@ -52,7 +52,7 @@ def handle_modification(files, modification, mode, apply_to):
|
||||
handle_file_modification(original_file, duplicate_file, modification)
|
||||
else:
|
||||
print(f"Duplicate file (unmodified): {duplicate_file}")
|
||||
else:
|
||||
elif modification != 'show':
|
||||
print(f"Original file kept: {original_file}")
|
||||
print()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user