手頭上有一批數(shù)據(jù),由于采集的時候是按照模板生產(chǎn)的,需要將其中的mdb改成X_XXXX_XX_XX_*X的形式,數(shù)據(jù)文件的組織方式如下:
需要達(dá)到的效果很簡單,如下圖:
用Python試了一下,初步解決了問題,但是不甚完美,但是還是需要修改,有時間再修改下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 |
# -*- coding:gbk -*- import os,shutil dics={'5000':'H','10000':'G'} def changeMdbName(inpath,outpath): for fdir in os.listdir(inpath): newfilen=returnNewName(fdir,outpath) oldpath=inpath+os.sep+fdir+os.sep+'model.mdb' newpath=outpath+os.sep+newfilen+'.mdb' shutil.copy(oldpath,newpath) print newpath def returnNewName(filename,outpath): newfn='' for dic in dics.keys(): if (filename.find(dic)<>-1): indentification=dics[dic] newfn=filename.replace(dic,'') newfn=addZero(newfn) newfn=newfn.replace('-','_') newfn=indentification+'_'+newfn if(newfn.endswith('_')): newfn=newfn[:-1] if(len(newfn)>23): myfile.write(newfn+' length:'+str(len(newfn))+'n') newfn='A'+newfn return newfn def addZero(fn): nfn='' fns=fn.split('-') for f in fns: if(len(f)==1): index=fns.index(f) fns[index]='0'+fns[index] for f in fns: nfn=nfn+f+'-' return nfn inputpath=r"C:data最終成果數(shù)據(jù)(8月1日)mdb合并數(shù)據(jù)5千mdb"outputpath=r"C:datamdb5000mdb" txtpath=outputpath+os.sep+'log_changeMdbName.txt'myfile=open(txtpath,'w') myfile.write("length must <=23,because when add'_DGXJQX',Feature name must <=30n") changeMdbName(inputpath,outputpath) myfile.close() print "Done" |






