Created
May 19, 2023 16:34
-
-
Save Hosuke/42b3029294137862f4b408e88366d313 to your computer and use it in GitHub Desktop.
lido_renaming_script.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Get the current directory | |
dir_path = os.getcwd() | |
# Traverse all files and subdirectories in the current directory | |
for root, dirs, files in os.walk(dir_path): | |
for file_name in files: | |
# Replace 'accounting_ethereum' with 'ethereum_accounting' in the file content | |
with open(os.path.join(root, file_name), 'r') as f: | |
content = f.read() | |
if 'lido_accounting_ethereum' in content: | |
new_content = content.replace('lido_accounting_ethereum', 'lido_ethereum_accounting') | |
with open(os.path.join(root, file_name), 'w') as f: | |
f.write(new_content) | |
print(f'Replaced "accounting_ethereum" with "ethereum_accounting" in {file_name}') | |
# Replace 'accounting_ethereum' with 'ethereum_accounting' in the file name | |
if 'accounting_ethereum' in file_name: | |
new_file_name = file_name.replace('accounting_ethereum', 'ethereum_accounting') | |
# Rename the file | |
os.rename(os.path.join(root, file_name), os.path.join(root, new_file_name)) | |
print(f'Renamed {file_name} to {new_file_name}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment