From 75cdf367b27b5416653843f1db05da11d67334dd Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 22 Aug 2023 22:42:57 +0200 Subject: [PATCH] Solved bug --- replace_string.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/replace_string.py b/replace_string.py index 4370a20..3d6d034 100644 --- a/replace_string.py +++ b/replace_string.py @@ -22,16 +22,10 @@ def process_directory(base_path, old_string, new_string, recursive, folder, file dirs[:] = [d for d in dirs if not d.startswith(".")] filenames = [f for f in filenames if not f.startswith(".")] - if folder: - for d in dirs: - if old_string in d: - old_path = os.path.join(root, d) - new_path = os.path.join(root, d.replace(old_string, new_string)) - if verbose: - print(f"Renaming directory from: {old_path} to: {new_path}") - if not preview: - os.rename(old_path, new_path) - + if content: + for f in filenames: + replace_content(os.path.join(root, f), old_string, new_string, preview, verbose) + if files: for f in filenames: if old_string in f: @@ -41,11 +35,17 @@ def process_directory(base_path, old_string, new_string, recursive, folder, file print(f"Renaming file from: {old_path} to: {new_path}") if not preview: os.rename(old_path, new_path) + + if folder: + for d in dirs: + if old_string in d: + old_path = os.path.join(root, d) + new_path = os.path.join(root, d.replace(old_string, new_string)) + if verbose: + print(f"Renaming directory from: {old_path} to: {new_path}") + if not preview: + os.rename(old_path, new_path) - if content: - for f in filenames: - replace_content(os.path.join(root, f), old_string, new_string, preview, verbose) - if not recursive: break