您的位置:首页 > 编程语言 > Python开发

python批量重命名文件

2016-07-18 12:26 381 查看
#!/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')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: