|
|
|
|
|
import os |
|
import re |
|
import sys |
|
from pathlib import Path |
|
|
|
def remove_boys(target_dir='.'): |
|
|
|
target_path = Path(target_dir) |
|
|
|
|
|
for file_path in target_path.rglob('*.txt'): |
|
with open(file_path, 'r+', encoding='utf-8') as f: |
|
content = f.read() |
|
|
|
content = re.sub(r',\s*([1-9]boy|[1-9]boys|[1-9]girl|[1-9]girls)', '', content) |
|
|
|
content = re.sub(r'([1-9]boy|[1-9]boys|[1-9]girl|[1-9]girls)', '', content) |
|
|
|
content = re.sub(r',\s*,', ',', content) |
|
content = re.sub(r',\s*$', '', content) |
|
content = re.sub(r'^\s*,', '', content) |
|
content = re.sub(r'\s*,\s*', ', ', content) |
|
|
|
content = re.sub(r',\s*$', '', content) |
|
|
|
content = re.sub(r'^\s*,', '', content) |
|
|
|
content = re.sub(r',\s*,', ',', content) |
|
f.seek(0) |
|
f.write(content) |
|
f.truncate() |
|
|
|
if __name__ == "__main__": |
|
|
|
target_dir = sys.argv[1] if len(sys.argv) > 1 else '.' |
|
remove_boys(target_dir) |
|
|
|
|