本帖最后由 qq253040425 于 2015-11-18 17:40 编辑
回复 18# 依山居
谢谢大神帮助,已搞定!虽然主体部分的逻辑完全看不懂!但是测试能用了! 用百万级的.del文件测试过了,没啥问题的样子- import os
- import time
- import datetime
-
- print (time.strftime("%Y-%m-%d %H:%M:%S %p", time.localtime()))
- print ('Check start, remove the ok file ... ')
-
- lst_last=datetime.date(datetime.date.today().year,datetime.date.today().month,1)-datetime.timedelta(1)
- workdir='D:\\IMPDATA\\FTPFILE\\'+lst_last.strftime('%Y-%m-%d')+'\\cqcs\\817'
- okfile=workdir+'\check.ok'
-
- if os.path.exists(okfile):
- os.remove(okfile)
-
- newtxt=[]
- for dirpath,dirs,files in os.walk(workdir):
-
- for file in files:
-
- if os.path.splitext(file)[1] == '.del':
-
- vfname=os.path.join(dirpath,file)
- print ('Check file: ' + vfname)
-
- with open(vfname) as f:
- txt=f.readlines()
- txt=[r.rstrip() for r in txt]
- rn=len(txt)
- print("Rowscount:",rn)
- newtxt=[txt[r-1][:]+txt[r][:] if ( ('\"' not in txt[r][0]) ) else txt[r] for r in range(rn) ]
- newtxt=[r+"\n" for r in newtxt if r.count('\"')%2==0]
- f.close()
-
- nfname= vfname+'_new'
- with open(nfname,"w+") as f:
- f.writelines(newtxt)
- f.close()
-
- os.remove(vfname)
- os.rename(nfname,vfname)
-
- print ('Check over, touch the ok file ...')
- with open(okfile,'w+') as f:
- f.writelines('')
- f.close()
- print (time.strftime("%Y-%m-%d %H:%M:%S %p", time.localtime()))
复制代码
|