mirror of
https://github.com/kevinveenbirkenbach/duplicate-file-handler.git
synced 2024-11-15 02:21:03 +01:00
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
|
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)
|