37,720
社区成员
发帖
与我相关
我的任务
分享
#! /usr/bin/env python
import os
for i in range(1,235):
fname = '%05d' % i
if os.path.isfile(fname):
new_name = fname + (i%2==0 and 'm' or 'n')
os.rename(fname,new_name)
print 'DONE'
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import os
filelist = ['00001', '00002', '00003', '00004', '00005', '00006', '00007', '00008', '00009', '00010']
pattm = '\d{4}(1|3|5|7|9)' #奇数
pattn = '\d{4}(0|2|4|6|8)' #偶数
mcount = 1
ncount = 1
for file in filelist:
rsm = re.match( pattm, file )
if rsm is not None:
newfile = '%05dm' % mcount
print file, '->', newfile
os.rename( file, newfile )
mcount += 1
else :
rsn = re.match( pattn, file )
if rsn is not None:
newfile = '%05dn' % ncount
print file, '->', newfile
os.rename( file, newfile )
ncount += 1
#! -*- encoding:UTF-8 -*-
import re
filelist = ['00001','00002','00003','00004','00005','00006','00007','00008','00009','00010']
pattm = '\d{4}(1|3|5|7|9)' #奇数
pattn = '\d{4}(0|2|4|6|8)' #偶数
rslist = []
mcount = 1
ncount = 1
for file in filelist:
rsm = re.match(pattm, file)
rsn = re.match(pattn, file)
if rsm is not None:
rslist.append(re.sub(pattm, (str(mcount) + 'm'), file))
mcount += 1
elif rsn is not None:
rslist.append(re.sub(pattn, str(ncount) + 'n', file))
ncount += 1
print rslist