-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch.py
27 lines (22 loc) · 1012 Bytes
/
ch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
# Directories to search for files
directories = ["_posts", "pages"]
# Loop through the specified directories
for directory in directories:
# Check if the directory exists
if os.path.exists(directory):
# Loop through all the files in the directory
for filename in os.listdir(directory):
# Check if the file ends with '-cn.md'
if filename.endswith('-cn.md'):
# Create the new filename by replacing '-cn.md' with '-zh.md'
new_filename = filename.replace('-cn.md', '-zh.md')
# Get the full path for the old and new filenames
old_file = os.path.join(directory, filename)
new_file = os.path.join(directory, new_filename)
# Rename the file
os.rename(old_file, new_file)
# Print the renaming result
print(f"Renamed: {filename} -> {new_filename}")
else:
print(f"Directory {directory} does not exist.")