mirror of
https://github.com/kevinveenbirkenbach/bulk-string-replacer.git
synced 2024-11-22 11:01:03 +01:00
show replace content just if to replace content exist
This commit is contained in:
parent
71f5db9f74
commit
df49d43c50
@ -5,14 +5,15 @@ def replace_content(path, old_string, new_string, preview, verbose):
|
|||||||
with open(path, 'r', encoding='utf-8') as f:
|
with open(path, 'r', encoding='utf-8') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
|
||||||
new_content = content.replace(old_string, new_string)
|
if old_string in content: # Prüfen, ob der alte String im Inhalt vorkommt
|
||||||
|
new_content = content.replace(old_string, new_string)
|
||||||
if verbose:
|
|
||||||
print(f"Replacing content in: {path}")
|
|
||||||
|
|
||||||
if not preview:
|
if verbose:
|
||||||
with open(path, 'w', encoding='utf-8') as f:
|
print(f"Replacing content in: {path}")
|
||||||
f.write(new_content)
|
|
||||||
|
if not preview:
|
||||||
|
with open(path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(new_content)
|
||||||
|
|
||||||
def process_directory(base_path, old_string, new_string, recursive, folder, files, content, preview, verbose, hidden):
|
def process_directory(base_path, old_string, new_string, recursive, folder, files, content, preview, verbose, hidden):
|
||||||
for root, dirs, filenames in os.walk(base_path):
|
for root, dirs, filenames in os.walk(base_path):
|
||||||
|
Loading…
Reference in New Issue
Block a user