From ccd1eecdfc6dc25ebfed1b277fa05d0bf52df17d Mon Sep 17 00:00:00 2001 From: Martin Nestorov Date: Wed, 22 May 2024 10:17:21 +0300 Subject: [PATCH] Recreating Directory Structure: The process_directory function calculates the relative path of each PHP file and creates the corresponding subdirectory in the output directory. Adjusting the Obfuscation Function: The obfuscate_php function now creates the target directory if it doesn't exist, ensuring that the directory structure is maintained. With these changes, the script will replicate the directory structure of the input project in the output directory, maintaining the same hierarchy for obfuscated files. --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 247b366..c8564b8 100644 --- a/main.py +++ b/main.py @@ -36,6 +36,9 @@ def obfuscate_php(input_file, obfuscation_options, create_backup, output_directo logging.info(f"Created backup: {backup_file}") try: + # Create the directory if it doesn't exist + os.makedirs(output_directory, exist_ok=True) + output_file = os.path.join(output_directory, f"obfuscated_{os.path.basename(input_file)}") logging.info(f"Obfuscating {input_file}") @@ -68,7 +71,11 @@ def process_directory(directory, obfuscation_options, exclude_list, create_backu logging.info(f"Skipping {input_file}: excluded") continue - file_list.append((input_file, obfuscation_options, create_backup, output_directory)) + # Calculate the target directory in the output structure + relative_path = os.path.relpath(root, directory) + target_directory = os.path.join(output_directory, relative_path) + + file_list.append((input_file, obfuscation_options, create_backup, target_directory)) progress_bar = tqdm(total=len(file_list), desc="Obfuscating", unit="file")