import os root_dir = r'C:\Users\L1822\xinmi\MuMuAINovel' old_text = 'MuMuAINovel' new_text = '墨木灵思' exclude_dirs = {'.git', 'node_modules', '.work', 'images'} exclude_files = {'package-lock.json', 'pnpm-lock.yaml'} for root, dirs, files in os.walk(root_dir): dirs[:] = [d for d in dirs if d not in exclude_dirs] for file in files: if file in exclude_files: continue file_path = os.path.join(root, file) try: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() if old_text in content: new_content = content.replace(old_text, new_text) with open(file_path, 'w', encoding='utf-8') as f: f.write(new_content) print(f'Replaced in: {file_path}') except Exception as e: # Skip binary files or encoding errors pass