mirror of
https://github.com/kevinveenbirkenbach/bulk-string-replacer.git
synced 2025-09-08 19:27:13 +02:00
Optimized string replace to catch utf8 errors
This commit is contained in:
@@ -2,6 +2,7 @@ import os
|
||||
import argparse
|
||||
|
||||
def replace_content(path, old_string, new_string, preview, verbose):
|
||||
try:
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
@@ -14,6 +15,9 @@ def replace_content(path, old_string, new_string, preview, verbose):
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
except UnicodeDecodeError as e:
|
||||
print_verbose(f"Warning: Unicode decode error encountered in file {path}. Skipping file.", verbose)
|
||||
|
||||
def print_verbose(content,verbose):
|
||||
if verbose:
|
||||
print(content)
|
||||
|
Reference in New Issue
Block a user