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')
# -*- 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——4Dict和Set类型
- Python中排序常用到的sort 、sorted和argsort函数
- Python之decorator,闭包,异常
- Python——3条件判断和循环
- python 使用zip合并相邻的列表项
- Python——2list和tuple类型
- 使用python处理中文csv文件,并让excel正确显示中文(避免乱码)
- Python——1变量和数据类型(内含其他知识点链接)
- 浅谈python字符串方法的简单使用
- 安装zeromq以及zeromq的python示例
- python爬虫之豆瓣图书信息几行字
- python爬虫神器PyQuery的使用方法
- ubuntu下如何在python中安装mysql,并测试
- Python多线程模块
- 【python】lxml-The E-factory
- python开发环境 sublime3配置
- Python面向对象小结
- python 接口自动化测试--代码实现(八)
- Python装饰器
- python 接口自动化测试--代码实现(七)