仅供python环境使用,快捷方便直接一键式
import os
# 指定目录
directory = r'F:\backups\my\chajian'
# 旧后缀和新后缀
old_ext = '.txt'
new_ext = '.dat'
# 遍历指定目录
for filename in os.listdir(directory):
# 检查文件是否以旧后缀结尾
if filename.endswith(old_ext):
# 构造旧文件的完整路径
old_file = os.path.join(directory, filename)
# 构造新文件名
new_filename = filename[:-len(old_ext)] + new_ext
# 构造新文件的完整路径
new_file = os.path.join(directory, new_filename)
# 重命名文件
os.rename(old_file, new_file)
print(f'Renamed "{old_file}" to "{new_file}"')
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容