import os def replace_url_in_file(file_path, old_url, new_url): try: with open(file_path, 'r', encoding='utf-8') as file: filedata = file.read() filedata = filedata.replace(old_url, new_url) with open(file_path, 'w', encoding='utf-8') as file: file.write(filedata) except Exception as e: pass def replace_url_in_folder(folder_path, old_url, new_url): for root, dirs, files in os.walk(folder_path): for file in files: file_path = os.path.join(root, file) replace_url_in_file(file_path, old_url, new_url) folder_path = 'stable-diffusion-webui-forge/' # 替换为你的文件夹路径 old_hugging = 'huggingface.co' # 替换为你要替换的旧URL new_hugging = 'hf-mirror.com' # 替换为你要替换的新URL old_git = "https://github.com" new_git = "https://gh.con.sh/https://github.com" replace_url_in_folder(folder_path, old_hugging, new_hugging) replace_url_in_folder(folder_path, old_git, new_git) print("ALL DONE!")