- 论坛徽章:
- 0
|
- #!/usr/bin/env python
- # -*- coding:utf-8 -*-
- import os
- import re
- src = 'g:/test'
- def get_file(spath):
- l_file=[]
- if os.path.isdir(spath):
- for f in os.listdir(spath):
- f1=os.path.join(spath,f)
- if os.path.isfile(f1):
- l_file.append(f1)
- return l_file
-
- def proc_file(sfile):
- r_list=[]
- l_gt=[]
- with open(sfile) as f:
- for line in f:
- r_list.extend(re.findall('[0-9]{4,}',line))
- for x in r_list:
- if int(x)>1000:
- l_gt.append(x)
- return l_gt
-
- r_f = get_file(src)
- if len(r_f)>0:
- for pf in r_f:
- l_gt_0=proc_file(pf)
- if len(l_gt_0)>0:
- print (pf,l_gt_0)
-
复制代码
1.txt
- sadsaf1025454512130dfdafd2104zcvcv
- 100
- 200dfsf
- sf6300sdf8550aaa
- ccc1001dfdf
- vv2006aa
- 1
- 23
复制代码
G:\code>python cu_lx1.py
g:/test\1.txt ['1025454512130', '2104', '6300', '8550', '1001', '2006']
g:/test\2.txt ['7300', '1003', '2008', '9663']
|
|