31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
import os
|
|
|
|
def rename_md_files(folder_path):
|
|
# 获取文件夹中所有的文件
|
|
files = [f for f in os.listdir(folder_path) if f.endswith('.md')]
|
|
|
|
# 对文件进行排序,确保系统顺序可以按字母表或当前文件名顺序
|
|
files.sort()
|
|
|
|
if len(files) > 209:
|
|
print(f"警告:文件夹中有 {len(files)} 个 `.md` 文件,但脚本只支持重命名到 209。")
|
|
print("请确保文件数量不超出范围。")
|
|
return
|
|
|
|
# 重命名文件
|
|
for index, file in enumerate(files, start=1):
|
|
# 构建新文件名
|
|
new_name = f"{index}.md"
|
|
# 获取完整路径
|
|
old_path = os.path.join(folder_path, file)
|
|
new_path = os.path.join(folder_path, new_name)
|
|
|
|
# 重命名文件
|
|
os.rename(old_path, new_path)
|
|
print(f"重命名: {old_path} -> {new_path}")
|
|
|
|
print("所有 `.md` 文件已成功重命名!")
|
|
|
|
# 指定文件夹路径
|
|
folder_path = "/home/ubuntu/50T/fsy/wl/articles/only_mds"
|
|
rename_md_files(folder_path) |