python脚本实现自动为png类型图片添加@2x
#!/usr/bin/env python
#coding=utf-8
import os
def rename(path):
for item in os.listdir(path):
# print 'filename: %s' % os.path.splitext(item)[0]
fname = os.path.splitext(item)[0]
sufix = os.path.splitext(item)[1][1:]
if sufix == "png":
addAt(fname,sufix)
pass
def addAt(filename,sufix):
origin = '%s.%s' % (filename,sufix)
desc = '%s@2x.%s' % (filename,sufix)
os.rename(origin,desc)
print 'rename [%s] to [%s]' % (origin,desc)
pass
if __name__ == "__main__":
dirname = r'./'
rename(dirname)
#coding=utf-8
import os
def rename(path):
for item in os.listdir(path):
# print 'filename: %s' % os.path.splitext(item)[0]
fname = os.path.splitext(item)[0]
sufix = os.path.splitext(item)[1][1:]
if sufix == "png":
addAt(fname,sufix)
pass
def addAt(filename,sufix):
origin = '%s.%s' % (filename,sufix)
desc = '%s@2x.%s' % (filename,sufix)
os.rename(origin,desc)
print 'rename [%s] to [%s]' % (origin,desc)
pass
if __name__ == "__main__":
dirname = r'./'
rename(dirname)