#!/usr/bin/python
# -*- coding:UTF-8 -*-
import os
def rename_file(path):
for file in os.listdir(path):if os.path.isfile(os.path.join(path,file)) == True:
if file.find('.json') < 0:
newname = file + '.json'
os.rename(os.path.join(path,file),os.path.join(path,newname))
print file,'ok'
else:
continue
else:
continue
print rename_file('/root/hosts')
本文介绍了一个简单的Python脚本,用于在指定目录中批量将非.JSON扩展名的文件重命名为.JSON文件。该脚本通过检查文件是否为普通文件且不以.JSON结尾来确定是否进行重命名。

495

被折叠的 条评论
为什么被折叠?



